Skip to content

Commit 1997ea6

Browse files
Automatic merge of master into galahad
2 parents 71a020d + 64ddb47 commit 1997ea6

File tree

20 files changed

+472
-303
lines changed

20 files changed

+472
-303
lines changed

espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/descriptors/Symbol.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ public static void ensureInitialized() {
617617
public static final Symbol<Name> HIDDEN_INTERNAL_TYPE = StaticSymbols.putName("0HIDDEN_INTERNAL_TYPE");
618618
public static final Symbol<Name> rawType = StaticSymbols.putName("rawType");
619619

620+
public static final Symbol<Name> espresso_polyglot = StaticSymbols.putName("espresso.polyglot");
621+
620622
// Class redefinition plugin helpers
621623
public static final Symbol<Name> flushFromCaches = StaticSymbols.putName("flushFromCaches");
622624
public static final Symbol<Name> generateProxyClass = StaticSymbols.putName("generateProxyClass");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.espresso.classfile.tables;
24+
25+
import java.util.ArrayList;
26+
import java.util.concurrent.locks.ReadWriteLock;
27+
28+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
29+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
30+
31+
public abstract class AbstractModuleTable<M, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable<ME, AbstractModuleTable.ModuleData<M>> {
32+
public AbstractModuleTable(ReadWriteLock lock) {
33+
super(lock);
34+
}
35+
36+
public ME createAndAddEntry(Symbol<Name> name, String version, String location, boolean isOpen, M module) {
37+
return createAndAddEntry(name, new ModuleData<>(version, location, module, isOpen));
38+
}
39+
40+
public ME createUnnamedModuleEntry(M module) {
41+
ME result = createEntry(null, new ModuleData<>(null, null, module, true));
42+
result.setCanReadAllUnnamed();
43+
return result;
44+
}
45+
46+
public static final class ModuleData<M> {
47+
private final String version;
48+
private final String location;
49+
private final boolean isOpen;
50+
private final M module;
51+
52+
public ModuleData(String version, String location, M module, boolean isOpen) {
53+
this.version = version;
54+
this.location = location;
55+
this.isOpen = isOpen;
56+
this.module = module;
57+
}
58+
}
59+
60+
public abstract static class AbstractModuleEntry<M> extends EntryTable.NamedEntry {
61+
private final boolean isOpen;
62+
private M module;
63+
private String version;
64+
private String location;
65+
private boolean canReadAllUnnamed;
66+
private ArrayList<AbstractModuleEntry<M>> reads;
67+
68+
protected AbstractModuleEntry(Symbol<Name> name, ModuleData<M> data) {
69+
super(name);
70+
this.version = data.version;
71+
this.location = data.location;
72+
this.isOpen = data.isOpen;
73+
this.module = data.module;
74+
}
75+
76+
public void addReads(AbstractModuleEntry<M> from) {
77+
if (!isNamed()) {
78+
return;
79+
}
80+
synchronized (this) {
81+
if (from == null) {
82+
setCanReadAllUnnamed();
83+
return;
84+
}
85+
if (reads == null) {
86+
reads = new ArrayList<>();
87+
}
88+
if (!contains(from)) {
89+
reads.add(from);
90+
}
91+
}
92+
}
93+
94+
public boolean canRead(AbstractModuleEntry<M> m, boolean mIsJavaBase) {
95+
if (!isNamed() || mIsJavaBase) {
96+
return true;
97+
}
98+
/*
99+
* Acceptable access to a type in an unnamed module. Note that since unnamed modules can
100+
* read all unnamed modules, this also handles the case where module_from is also
101+
* unnamed but in a different class loader.
102+
*/
103+
if (!m.isNamed() && canReadAllUnnamed) {
104+
return true;
105+
}
106+
synchronized (this) {
107+
if (hasReads()) {
108+
return contains(m);
109+
} else {
110+
return false;
111+
}
112+
}
113+
}
114+
115+
private boolean contains(AbstractModuleEntry<M> from) {
116+
return reads.contains(from);
117+
}
118+
119+
public void setModule(M module) {
120+
assert this.module == null;
121+
this.module = module;
122+
}
123+
124+
public M module() {
125+
return module;
126+
}
127+
128+
public String version() {
129+
return version;
130+
}
131+
132+
public String location() {
133+
return location;
134+
}
135+
136+
public void setCanReadAllUnnamed() {
137+
canReadAllUnnamed = true;
138+
}
139+
140+
public boolean isOpen() {
141+
return isOpen;
142+
}
143+
144+
public boolean isNamed() {
145+
return getName() != null;
146+
}
147+
148+
public boolean hasReads() {
149+
return reads != null && !reads.isEmpty();
150+
}
151+
152+
public void setVersionAndLocation(String moduleVersion, String moduleLocation) {
153+
assert version == null && location == null;
154+
this.version = moduleVersion;
155+
this.location = moduleLocation;
156+
}
157+
}
158+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
package com.oracle.truffle.espresso.classfile.tables;
24+
25+
import java.util.ArrayList;
26+
import java.util.concurrent.locks.ReadWriteLock;
27+
28+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
29+
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
30+
31+
public abstract class AbstractPackageTable<M, PE extends AbstractPackageTable.AbstractPackageEntry<M, ME>, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable<PE, ME> {
32+
public AbstractPackageTable(ReadWriteLock lock) {
33+
super(lock);
34+
}
35+
36+
public abstract static class AbstractPackageEntry<M, ME extends AbstractModuleTable.AbstractModuleEntry<M>> extends EntryTable.NamedEntry {
37+
protected AbstractPackageEntry(Symbol<Name> name, ME module) {
38+
super(name);
39+
this.module = module;
40+
}
41+
42+
private final ME module;
43+
private ArrayList<ME> exports;
44+
private boolean isUnqualifiedExported;
45+
private boolean isExportedAllUnnamed;
46+
private String bootClasspathLocation;
47+
48+
public void addExports(ME m) {
49+
if (isUnqualifiedExported()) {
50+
return;
51+
}
52+
synchronized (this) {
53+
if (m == null) {
54+
setUnqualifiedExports();
55+
}
56+
if (exports == null) {
57+
exports = new ArrayList<>();
58+
}
59+
if (!contains(m)) {
60+
exports.add(m);
61+
}
62+
}
63+
}
64+
65+
public boolean isQualifiedExportTo(ME m) {
66+
if (isExportedAllUnnamed() && !m.isNamed()) {
67+
return true;
68+
}
69+
if (isUnqualifiedExported() || exports == null) {
70+
return false;
71+
}
72+
return contains(m);
73+
}
74+
75+
public boolean isUnqualifiedExported() {
76+
return module().isOpen() || isUnqualifiedExported;
77+
}
78+
79+
public void setUnqualifiedExports() {
80+
if (isUnqualifiedExported()) {
81+
return;
82+
}
83+
isUnqualifiedExported = true;
84+
isExportedAllUnnamed = true;
85+
exports = null;
86+
}
87+
88+
public boolean isExportedAllUnnamed() {
89+
return module().isOpen() || isExportedAllUnnamed;
90+
}
91+
92+
public void setExportedAllUnnamed() {
93+
if (isExportedAllUnnamed()) {
94+
return;
95+
}
96+
synchronized (this) {
97+
isExportedAllUnnamed = true;
98+
}
99+
}
100+
101+
public boolean contains(ME m) {
102+
return exports.contains(m);
103+
}
104+
105+
public ME module() {
106+
return module;
107+
}
108+
109+
public void setBootClasspathLocation(String bootClasspathLocation) {
110+
this.bootClasspathLocation = bootClasspathLocation;
111+
}
112+
113+
public String getBootClasspathLocation() {
114+
return bootClasspathLocation;
115+
}
116+
}
117+
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/impl/EntryTable.java renamed to espresso/src/com.oracle.truffle.espresso.classfile/src/com/oracle/truffle/espresso/classfile/tables/EntryTable.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
* or visit www.oracle.com if you need additional information or have any
2121
* questions.
2222
*/
23+
package com.oracle.truffle.espresso.classfile.tables;
2324

24-
package com.oracle.truffle.espresso.impl;
25-
26-
import java.util.Collection;
27-
import java.util.Collections;
2825
import java.util.HashMap;
2926
import java.util.Objects;
3027
import java.util.concurrent.locks.Lock;
3128
import java.util.concurrent.locks.ReadWriteLock;
29+
import java.util.function.Consumer;
3230

3331
import com.oracle.truffle.espresso.classfile.descriptors.Symbol;
3432
import com.oracle.truffle.espresso.classfile.descriptors.Symbol.Name;
@@ -45,9 +43,16 @@ protected EntryTable(ReadWriteLock lock) {
4543
}
4644

4745
@SuppressWarnings("try")
48-
public Collection<T> values() {
46+
public void collectValues(Consumer<T> consumer) {
47+
try (BlockLock block = read()) {
48+
entries.values().forEach(consumer);
49+
}
50+
}
51+
52+
@SuppressWarnings({"try", "unchecked", "rawtypes"})
53+
public Symbol<Name>[] getKeys() {
4954
try (BlockLock block = read()) {
50-
return Collections.unmodifiableCollection(entries.values());
55+
return entries.keySet().toArray(new Symbol[entries.size()]);
5156
}
5257
}
5358

@@ -88,27 +93,27 @@ protected NamedEntry(Symbol<Name> name) {
8893

8994
protected final Symbol<Name> name;
9095

91-
public Symbol<Name> getName() {
96+
public final Symbol<Name> getName() {
9297
return name;
9398
}
9499

95-
public String getNameAsString() {
100+
public final String getNameAsString() {
96101
if (name == null) {
97102
return "unnamed";
98103
}
99104
return name.toString();
100105
}
101106

102107
@Override
103-
public int hashCode() {
108+
public final int hashCode() {
104109
if (name == null) {
105110
return 0;
106111
}
107112
return name.hashCode();
108113
}
109114

110115
@Override
111-
public boolean equals(Object obj) {
116+
public final boolean equals(Object obj) {
112117
if (obj instanceof NamedEntry) {
113118
return Objects.equals(((NamedEntry) obj).getName(), this.getName());
114119
}

0 commit comments

Comments
 (0)