Skip to content

Commit 6a4f3b6

Browse files
[GR-24257] [GR-10998] Move Java.extend implementation to Truffle.
PullRequest: js/1735
2 parents cf685a8 + c3de480 commit 6a4f3b6

File tree

16 files changed

+34
-2004
lines changed

16 files changed

+34
-2004
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ The main focus is on user-observable behavior of the engine.
88
* Fixed field/getter/setter access order in nashorn-compat mode, see [issue #343](https://github.com/graalvm/graaljs/issues/343).
99
* ScriptEngine: Fixed "Multiple applicable overloads found" error in nashorn-compat mode, see [issue #286](https://github.com/graalvm/graaljs/issues/286).
1010
* ScriptEngine: Enabled low precedence lossy number, string-to-boolean, and number-to-boolean conversions in nashorn-compat mode.
11+
* Fixed `Java.extend` to respect `HostAccess.Builder.allowImplementations`, see [issue #294](https://github.com/graalvm/graaljs/issues/294).
12+
* Added Java host interop support for mapping JS objects to abstract classes (if `HostAccess` allows it).
1113
* `js.foreign-object-prototype` is a supported option to set JavaScript prototypes for foreign objects mimicing JavaScript types. It was renamed from `js.experimental-foreign-object-prototype`.
1214
* Changed `ToPrimitive` abstract operation to follow the specification for foreign objects. `InteropLibrary.toDisplayString` is not used by `ToPrimitive/ToString` conversions anymore.
1315

graal-js/mx.graal-js/mx_graal_js.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ def is_included(path):
306306
truffle_jars=[
307307
'graal-js:GRAALJS',
308308
'graal-js:ICU4J',
309-
'graal-js:ASM-7.1',
310-
'graal-js:ASM_TREE-7.1',
311-
'graal-js:ASM_ANALYSIS-7.1',
312-
'graal-js:ASM_COMMONS-7.1',
313-
'graal-js:ASM_UTIL-7.1',
314309
],
315310
support_distributions=[
316311
'graal-js:GRAALJS_GRAALVM_SUPPORT',

graal-js/mx.graal-js/suite.py

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{
2525
"name" : "regex",
2626
"subdir" : True,
27-
"version" : "7f8bd65da1e445cbd0ba927e94ea9e5937d01fd1",
27+
"version" : "0e9e7e3cfd6405dedc798c90b8ce12b041cf8c94",
2828
"urls" : [
2929
{"url" : "https://github.com/oracle/graal.git", "kind" : "git"},
3030
{"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},
@@ -69,77 +69,6 @@
6969
},
7070
},
7171

72-
"ASM-7.1" : {
73-
"moduleName" : "org.objectweb.asm",
74-
"sha1" : "fa29aa438674ff19d5e1386d2c3527a0267f291e",
75-
"sourceSha1" : "9d170062d595240da35301362b079e5579c86f49",
76-
"maven" : {
77-
"groupId" : "org.ow2.asm",
78-
"artifactId" : "asm",
79-
"version" : "7.1",
80-
},
81-
},
82-
83-
"ASM_TREE-7.1" : {
84-
"moduleName" : "org.objectweb.asm.tree",
85-
"sha1" : "a3662cf1c1d592893ffe08727f78db35392fa302",
86-
"sourceSha1" : "157238292b551de8680505fa2d19590d136e25b9",
87-
"maven" : {
88-
"groupId" : "org.ow2.asm",
89-
"artifactId" : "asm-tree",
90-
"version" : "7.1",
91-
},
92-
"dependencies" : [
93-
"ASM-7.1",
94-
],
95-
},
96-
97-
"ASM_ANALYSIS-7.1" : {
98-
"moduleName" : "org.objectweb.asm.tree.analysis",
99-
"sha1" : "379e0250f7a4a42c66c5e94e14d4c4491b3c2ed3",
100-
"sourceSha1" : "36789198124eb075f1a5efa18a0a7812fb16f47f",
101-
"maven" : {
102-
"groupId" : "org.ow2.asm",
103-
"artifactId" : "asm-analysis",
104-
"version" : "7.1",
105-
},
106-
"dependencies" : [
107-
"ASM_TREE-7.1",
108-
],
109-
},
110-
111-
"ASM_COMMONS-7.1" : {
112-
"moduleName" : "org.objectweb.asm.commons",
113-
"sha1" : "431dc677cf5c56660c1c9004870de1ed1ea7ce6c",
114-
"sourceSha1" : "a62ff3ae6e37affda7c6fb7d63b89194c6d006ee",
115-
"maven" : {
116-
"groupId" : "org.ow2.asm",
117-
"artifactId" : "asm-commons",
118-
"version" : "7.1",
119-
},
120-
"dependencies" : [
121-
"ASM-7.1",
122-
"ASM_TREE-7.1",
123-
"ASM_ANALYSIS-7.1",
124-
],
125-
},
126-
127-
"ASM_UTIL-7.1" : {
128-
"moduleName" : "org.objectweb.asm.util",
129-
"sha1" : "5b0b0f8cdb6c90582302ffcf5c20447206122f48",
130-
"sourceSha1" : "728ab1171a60dd2c408e6dd1d12fceb560635346",
131-
"maven" : {
132-
"groupId" : "org.ow2.asm",
133-
"artifactId" : "asm-util",
134-
"version" : "7.1",
135-
},
136-
"dependencies" : [
137-
"ASM-7.1",
138-
"ASM_TREE-7.1",
139-
"ASM_ANALYSIS-7.1",
140-
],
141-
},
142-
14372
"TEST262" : {
14473
"sha1" : "551f5233714aea646d97cfc97c1f4cc7f34bd683",
14574
"urls" : ["https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/truffle/js/test262-538fcd88.tar.bz2"],
@@ -203,9 +132,6 @@
203132
"com.oracle.truffle.js.codec",
204133
"com.oracle.truffle.js.runtime.doubleconv",
205134
"truffle:TRUFFLE_API",
206-
"ASM-7.1",
207-
"ASM_COMMONS-7.1",
208-
"ASM_UTIL-7.1",
209135
"ICU4J",
210136
],
211137
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR", "TRUFFLE_JS_FACTORY_PROCESSOR"],
@@ -479,7 +405,6 @@
479405
},
480406
"exports" : [
481407
"com.oracle.truffle.js.lang to org.graalvm.truffle",
482-
"com.oracle.truffle.js.runtime.java.adapter",
483408
],
484409
},
485410
"subDir" : "src",
@@ -493,11 +418,6 @@
493418
"sdk:GRAAL_SDK",
494419
],
495420
"exclude": [
496-
"ASM-7.1",
497-
"ASM_TREE-7.1",
498-
"ASM_ANALYSIS-7.1",
499-
"ASM_COMMONS-7.1",
500-
"ASM_UTIL-7.1",
501421
"ICU4J",
502422
],
503423
"description" : "Graal JavaScript engine",

graal-js/src/com.oracle.truffle.js.test/src/com/oracle/truffle/js/test/builtins/JavaBuiltinsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static String test(String sourceCode, String failedMessage, boolean allo
8686
assertTrue(failedMessage == null);
8787
return result.asString();
8888
} catch (Exception ex) {
89-
assertTrue(failedMessage != null);
89+
assertTrue(ex.getMessage(), failedMessage != null);
9090
assertTrue(ex.getMessage(), ex.getMessage().contains(failedMessage));
9191
return "FAILED_AS_EXPECTED";
9292
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/JavaBuiltins.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import com.oracle.truffle.api.interop.ArityException;
5656
import com.oracle.truffle.api.interop.InteropLibrary;
5757
import com.oracle.truffle.api.interop.InvalidArrayIndexException;
58+
import com.oracle.truffle.api.interop.UnknownIdentifierException;
5859
import com.oracle.truffle.api.interop.UnsupportedMessageException;
5960
import com.oracle.truffle.api.interop.UnsupportedTypeException;
6061
import com.oracle.truffle.api.library.CachedLibrary;
@@ -96,7 +97,6 @@
9697
import com.oracle.truffle.js.runtime.builtins.JSFunction;
9798
import com.oracle.truffle.js.runtime.builtins.JSFunctionData;
9899
import com.oracle.truffle.js.runtime.java.JavaAccess;
99-
import com.oracle.truffle.js.runtime.java.adapter.JavaAdapterFactory;
100100
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
101101
import com.oracle.truffle.js.runtime.objects.Undefined;
102102

@@ -359,15 +359,16 @@ protected Object extend(Object[] arguments) {
359359
types[i] = toHostClass(arguments[i], env);
360360
}
361361

362-
JavaAccess.checkAccess(types, getContext());
363-
364-
Class<?> result;
365-
if (types.length == 1 && classOverrides == null) {
366-
result = getContext().getJavaAdapterClassFor(types[0]);
367-
} else {
368-
result = JavaAdapterFactory.getAdapterClassFor(types, classOverrides);
362+
try {
363+
JavaAccess.checkAccess(types, getContext());
364+
if (classOverrides != null) {
365+
return env.createHostAdapterClassWithStaticOverrides(types, classOverrides);
366+
} else {
367+
return env.createHostAdapterClass(types);
368+
}
369+
} catch (Exception ex) {
370+
throw Errors.createTypeError(ex.getMessage(), ex, this);
369371
}
370-
return env.asHostSymbol(result);
371372
}
372373

373374
protected static boolean isType(Object obj, TruffleLanguage.Env env) {
@@ -537,7 +538,11 @@ abstract static class JavaSuperNode extends JSBuiltinNode {
537538
@Specialization
538539
@TruffleBoundary
539540
protected Object superAdapter(Object adapter) {
540-
return JavaAdapterFactory.getSuperAdapter(adapter);
541+
try {
542+
return InteropLibrary.getUncached().readMember(adapter, "super");
543+
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
544+
return Undefined.instance;
545+
}
541546
}
542547
}
543548

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/access/PropertyCacheNode.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@
7676
import com.oracle.truffle.js.runtime.builtins.JSRegExp;
7777
import com.oracle.truffle.js.runtime.builtins.JSString;
7878
import com.oracle.truffle.js.runtime.builtins.PrototypeSupplier;
79-
import com.oracle.truffle.js.runtime.java.adapter.JavaSuperAdapter;
8079
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
8180
import com.oracle.truffle.js.runtime.objects.JSLazyString;
8281
import com.oracle.truffle.js.runtime.objects.JSObject;
@@ -232,24 +231,6 @@ public boolean isValid() {
232231
}
233232
}
234233

235-
protected static final class JavaSuperAdapterCheckNode extends ReceiverCheckNode {
236-
private final Class<?> type;
237-
238-
protected JavaSuperAdapterCheckNode(JavaSuperAdapter adapter) {
239-
this.type = adapter.getAdapter().getClass();
240-
}
241-
242-
@Override
243-
public boolean accept(Object thisObj) {
244-
return thisObj instanceof JavaSuperAdapter && ((JavaSuperAdapter) thisObj).getAdapter().getClass() == type;
245-
}
246-
247-
@Override
248-
public DynamicObject getStore(Object thisObj) {
249-
throw Errors.shouldNotReachHere();
250-
}
251-
}
252-
253234
/**
254235
* Check the object shape by identity comparison.
255236
*/

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/function/JSNewNode.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,13 @@ private Object extend(Class<?> type, TruffleLanguage.Env env) {
246246
throwCannotExtendError(type);
247247
}
248248
// Equivalent to Java.extend(type)
249-
JavaAccess.checkAccess(new Class<?>[]{type}, context);
250-
Class<?> adapterClass = context.getJavaAdapterClassFor(type);
251-
return env.asHostSymbol(adapterClass);
249+
Class<?>[] types = new Class<?>[]{type};
250+
try {
251+
JavaAccess.checkAccess(types, context);
252+
return env.createHostAdapterClass(types);
253+
} catch (Exception ex) {
254+
throw Errors.createTypeError(ex.getMessage(), ex, this);
255+
}
252256
}
253257

254258
@Specialization(guards = {"!isJSFunction(target)", "!isJSAdapter(target)", "!isJSProxy(target)", "!isJavaPackage(target)", "!isForeignObject(target)"})

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/Errors.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ public static JSException createTypeError(String message, Node originatingNode)
132132
return JSException.create(JSErrorType.TypeError, message, originatingNode);
133133
}
134134

135+
@TruffleBoundary
136+
public static JSException createTypeError(String message, Throwable cause, Node originatingNode) {
137+
return JSException.create(JSErrorType.TypeError, message, cause, originatingNode);
138+
}
139+
135140
@TruffleBoundary
136141
public static JSException createTypeErrorCannotMixBigIntWithOtherTypes(Node originatingNode) {
137142
return createTypeError("Cannot mix BigInt and other types, use explicit conversions.", originatingNode);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/JSContext.java

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
import com.oracle.truffle.js.runtime.builtins.intl.JSSegmenter;
122122
import com.oracle.truffle.js.runtime.java.JavaImporter;
123123
import com.oracle.truffle.js.runtime.java.JavaPackage;
124-
import com.oracle.truffle.js.runtime.java.adapter.JavaAdapterFactory;
125124
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
126125
import com.oracle.truffle.js.runtime.objects.JSModuleRecord;
127126
import com.oracle.truffle.js.runtime.objects.JSObject;
@@ -326,8 +325,6 @@ public enum BuiltinFunctionKey {
326325
private final JSPrototypeData nullPrototypeData = new JSPrototypeData();
327326
private final JSPrototypeData inObjectPrototypeData = new JSPrototypeData();
328327

329-
private volatile ClassValue<Class<?>> javaAdapterClasses;
330-
331328
private final JSFunctionFactory functionFactory;
332329
private final JSFunctionFactory constructorFactory;
333330
private final JSFunctionFactory strictFunctionFactory;
@@ -1502,25 +1499,6 @@ public JSContextOptions getContextOptions() {
15021499
return contextOptions;
15031500
}
15041501

1505-
public Class<?> getJavaAdapterClassFor(Class<?> clazz) {
1506-
if (JSConfig.SubstrateVM) {
1507-
throw Errors.unsupported("JavaAdapter");
1508-
}
1509-
if (javaAdapterClasses == null) {
1510-
synchronized (this) {
1511-
if (javaAdapterClasses == null) {
1512-
javaAdapterClasses = new ClassValue<Class<?>>() {
1513-
@Override
1514-
protected Class<?> computeValue(Class<?> type) {
1515-
return JavaAdapterFactory.getAdapterClassFor(type);
1516-
}
1517-
};
1518-
}
1519-
}
1520-
}
1521-
return javaAdapterClasses.get(clazz);
1522-
}
1523-
15241502
public final boolean isMultiContext() {
15251503
return isMultiContext;
15261504
}

0 commit comments

Comments
 (0)