Skip to content

Commit ed83f3e

Browse files
committed
[GR-18657] [GR-11851] Miscellaneous compilation fixes.
PullRequest: js/1719
2 parents 3ce92a7 + 5e95b35 commit ed83f3e

File tree

8 files changed

+99
-25
lines changed

8 files changed

+99
-25
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,16 @@ protected DynamicObject getJSObject(DynamicObject thisObj,
422422
protected DynamicObject getForeignObject(Object thisObj,
423423
@CachedLibrary("thisObj") InteropLibrary interop,
424424
@CachedLibrary(limit = "3") InteropLibrary members,
425-
@Cached("create()") ImportValueNode toJSType) {
425+
@Cached("create()") ImportValueNode toJSType,
426+
@Cached BranchProfile errorBranch) {
426427
DynamicObject result = JSOrdinary.create(getContext());
427428

428429
try {
429430
if (interop.hasMembers(thisObj)) {
430431
Object keysObj = interop.getMembers(thisObj);
431432
long size = members.getArraySize(keysObj);
432433
if (size < 0 || size >= Integer.MAX_VALUE) {
434+
errorBranch.enter();
433435
throw Errors.createRangeErrorInvalidArrayLength();
434436
}
435437
for (int i = 0; i < size; i++) {
@@ -448,6 +450,7 @@ protected DynamicObject getForeignObject(Object thisObj,
448450
if (interop.hasArrayElements(thisObj)) {
449451
long size = interop.getArraySize(thisObj);
450452
if (size < 0 || size >= Integer.MAX_VALUE) {
453+
errorBranch.enter();
451454
throw Errors.createRangeErrorInvalidArrayLength();
452455
}
453456
for (long i = 0; i < size; i++) {
@@ -513,13 +516,15 @@ protected DynamicObject getForeignObjectSymbols(@SuppressWarnings("unused") Obje
513516
@Specialization(guards = {"isForeignObject(thisObj)", "!symbols"}, limit = "3")
514517
protected DynamicObject getForeignObjectNames(Object thisObj,
515518
@CachedLibrary("thisObj") InteropLibrary interop,
516-
@CachedLibrary(limit = "3") InteropLibrary members) {
519+
@CachedLibrary(limit = "3") InteropLibrary members,
520+
@Cached BranchProfile errorBranch) {
517521
Object[] array;
518522
if (interop.hasMembers(thisObj)) {
519523
try {
520524
Object keysObj = interop.getMembers(thisObj);
521525
long size = members.getArraySize(keysObj);
522526
if (size < 0 || size >= Integer.MAX_VALUE) {
527+
errorBranch.enter();
523528
throw Errors.createRangeErrorInvalidArrayLength();
524529
}
525530
array = new Object[(int) size];
@@ -819,12 +824,14 @@ protected DynamicObject keysOther(Object thisObj) {
819824
protected DynamicObject keysForeign(Object obj,
820825
@CachedLibrary("obj") InteropLibrary interop,
821826
@CachedLibrary(limit = "3") InteropLibrary members,
822-
@Cached BranchProfile growProfile) {
827+
@Cached BranchProfile growProfile,
828+
@Cached BranchProfile errorBranch) {
823829
if (interop.hasMembers(obj)) {
824830
try {
825831
Object keysObj = interop.getMembers(obj);
826832
long size = members.getArraySize(keysObj);
827833
if (size < 0 || size >= Integer.MAX_VALUE) {
834+
errorBranch.enter();
828835
throw Errors.createRangeErrorInvalidArrayLength();
829836
}
830837
if (size > 0) {
@@ -1060,11 +1067,13 @@ protected DynamicObject enumerableOwnPropertyNamesForeign(Object thisObj,
10601067
@CachedLibrary("thisObj") InteropLibrary interop,
10611068
@CachedLibrary(limit = "3") InteropLibrary members,
10621069
@Cached ImportValueNode importValue,
1063-
@Cached BranchProfile growProfile) {
1070+
@Cached BranchProfile growProfile,
1071+
@Cached BranchProfile errorBranch) {
10641072
try {
10651073
Object keysObj = interop.getMembers(thisObj);
10661074
long size = members.getArraySize(keysObj);
10671075
if (size < 0 || size >= Integer.MAX_VALUE) {
1076+
errorBranch.enter();
10681077
throw Errors.createRangeErrorInvalidArrayLength();
10691078
}
10701079
SimpleArrayList<Object> values = SimpleArrayList.create(size);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/lang/JavaScriptLanguage.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Arrays;
4545
import java.util.Collection;
4646
import java.util.List;
47+
import java.util.Objects;
4748

4849
import org.graalvm.options.OptionDescriptor;
4950
import org.graalvm.options.OptionDescriptors;
@@ -160,7 +161,7 @@ public final class JavaScriptLanguage extends AbstractJavaScriptLanguage {
160161
public static final String IMPLEMENTATION_NAME = "GraalVM JavaScript";
161162
public static final String ID = "js";
162163

163-
private volatile JSContext languageContext;
164+
@CompilationFinal private volatile JSContext languageContext;
164165
private volatile boolean multiContext;
165166

166167
private final Assumption promiseJobsQueueEmptyAssumption;
@@ -297,6 +298,7 @@ protected static JavaScriptNode parseInlineScript(JSContext context, Source code
297298

298299
@Override
299300
protected JSRealm createContext(Env env) {
301+
CompilerAsserts.neverPartOfCompilation();
300302
JSContext context = languageContext;
301303
if (context == null) {
302304
context = initLanguageContext(env);
@@ -314,6 +316,7 @@ protected JSRealm createContext(Env env) {
314316
}
315317

316318
private synchronized JSContext initLanguageContext(Env env) {
319+
CompilerAsserts.neverPartOfCompilation();
317320
JSContext curContext = languageContext;
318321
if (curContext != null) {
319322
assert curContext.getContextOptions().equals(JSContextOptions.fromOptionValues(env.getOptions()));
@@ -335,6 +338,7 @@ protected void initializeContext(JSRealm realm) {
335338

336339
@Override
337340
protected boolean patchContext(JSRealm realm, Env newEnv) {
341+
CompilerAsserts.neverPartOfCompilation();
338342
assert realm.getContext().getLanguage() == this;
339343

340344
if (optionsAllowPreInitializedContext(realm.getEnv(), newEnv) && realm.patchContext(newEnv)) {
@@ -466,7 +470,7 @@ public void interopBoundaryExit(JSRealm realm) {
466470
if (!promiseJobsQueueEmptyAssumption.isValid()) {
467471
agent.processAllPromises(true);
468472
}
469-
if (realm.getContext().getContextOptions().isTestV8Mode()) {
473+
if (getJSContext().getContextOptions().isTestV8Mode()) {
470474
processTimeoutCallbacks(realm);
471475
}
472476
}
@@ -491,7 +495,7 @@ public Assumption getPromiseJobsQueueEmptyAssumption() {
491495
}
492496

493497
public JSContext getJSContext() {
494-
return languageContext;
498+
return Objects.requireNonNull(languageContext);
495499
}
496500

497501
public boolean bindMemberFunctions() {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import java.util.Set;
4444

4545
import com.oracle.truffle.api.dsl.Cached;
46+
import com.oracle.truffle.api.dsl.GenerateUncached;
4647
import com.oracle.truffle.api.dsl.Specialization;
4748
import com.oracle.truffle.api.frame.VirtualFrame;
4849
import com.oracle.truffle.api.instrumentation.Tag;
@@ -60,6 +61,7 @@
6061
import com.oracle.truffle.js.runtime.objects.Null;
6162
import com.oracle.truffle.js.runtime.util.JSClassProfile;
6263

64+
@GenerateUncached
6365
public abstract class GetPrototypeNode extends JavaScriptBaseNode {
6466
static final int MAX_SHAPE_COUNT = 2;
6567

@@ -101,26 +103,26 @@ static Property getPrototypeProperty(Shape shape) {
101103
}
102104

103105
@Specialization(guards = {"obj.getShape() == shape", "prototypeProperty != null"}, limit = "MAX_SHAPE_COUNT")
104-
public DynamicObject doCachedShape(DynamicObject obj,
106+
static DynamicObject doCachedShape(DynamicObject obj,
105107
@Cached("obj.getShape()") Shape shape,
106108
@Cached("getPrototypeProperty(shape)") Property prototypeProperty) {
107109
assert !JSGuards.isJSProxy(obj);
108110
return (DynamicObject) prototypeProperty.get(obj, shape);
109111
}
110112

111113
@Specialization(guards = "!isJSProxy(obj)", replaces = "doCachedShape")
112-
public DynamicObject doGeneric(DynamicObject obj) {
114+
static DynamicObject doGeneric(DynamicObject obj) {
113115
return JSObjectUtil.getPrototype(obj);
114116
}
115117

116118
@Specialization(guards = "isJSProxy(obj)")
117-
public DynamicObject doProxy(DynamicObject obj,
119+
static DynamicObject doProxy(DynamicObject obj,
118120
@Cached("create()") JSClassProfile jsclassProfile) {
119121
return JSObject.getPrototype(obj, jsclassProfile);
120122
}
121123

122124
@Specialization(guards = "!isDynamicObject(obj)")
123-
public DynamicObject doNotObject(@SuppressWarnings("unused") Object obj) {
125+
static DynamicObject doNotObject(@SuppressWarnings("unused") Object obj) {
124126
return Null.instance;
125127
}
126128
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -42,6 +42,7 @@
4242

4343
import com.oracle.truffle.api.dsl.Cached;
4444
import com.oracle.truffle.api.dsl.Cached.Shared;
45+
import com.oracle.truffle.api.dsl.GenerateUncached;
4546
import com.oracle.truffle.api.dsl.ImportStatic;
4647
import com.oracle.truffle.api.dsl.Specialization;
4748
import com.oracle.truffle.api.object.DynamicObject;
@@ -55,6 +56,7 @@
5556
/**
5657
* Implements abstract operation IsExtensible.
5758
*/
59+
@GenerateUncached
5860
@ImportStatic({JSShape.class})
5961
public abstract class IsExtensibleNode extends JavaScriptBaseNode {
6062

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/interop/KeyInfoNode.java

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,22 @@
4040
*/
4141
package com.oracle.truffle.js.nodes.interop;
4242

43+
import com.oracle.truffle.api.dsl.Bind;
44+
import com.oracle.truffle.api.dsl.Cached;
4345
import com.oracle.truffle.api.dsl.GenerateUncached;
4446
import com.oracle.truffle.api.dsl.Specialization;
47+
import com.oracle.truffle.api.library.CachedLibrary;
4548
import com.oracle.truffle.api.object.DynamicObject;
49+
import com.oracle.truffle.api.object.DynamicObjectLibrary;
50+
import com.oracle.truffle.api.object.Property;
4651
import com.oracle.truffle.js.nodes.JavaScriptBaseNode;
47-
import com.oracle.truffle.js.runtime.JSRuntime;
52+
import com.oracle.truffle.js.nodes.access.GetPrototypeNode;
53+
import com.oracle.truffle.js.nodes.access.IsExtensibleNode;
54+
import com.oracle.truffle.js.nodes.unary.IsCallableNode;
4855
import com.oracle.truffle.js.runtime.builtins.JSProxy;
56+
import com.oracle.truffle.js.runtime.objects.Accessor;
4957
import com.oracle.truffle.js.runtime.objects.JSObject;
58+
import com.oracle.truffle.js.runtime.objects.JSProperty;
5059
import com.oracle.truffle.js.runtime.objects.Null;
5160
import com.oracle.truffle.js.runtime.objects.PropertyDescriptor;
5261
import com.oracle.truffle.js.runtime.objects.Undefined;
@@ -70,11 +79,55 @@ public abstract class KeyInfoNode extends JavaScriptBaseNode {
7079

7180
public abstract boolean execute(DynamicObject receiver, String key, int query);
7281

73-
@Specialization
74-
static boolean member(DynamicObject target, String key, int query) {
82+
@Specialization(guards = {"!isJSProxy(target)", "property != null"}, limit = "2")
83+
static boolean cachedOwnProperty(DynamicObject target, String key, int query,
84+
@CachedLibrary("target") DynamicObjectLibrary objectLibrary,
85+
@Bind("objectLibrary.getProperty(target, key)") Property property,
86+
@Cached IsCallableNode isCallable) {
87+
if (JSProperty.isAccessor(property)) {
88+
Accessor accessor = (Accessor) objectLibrary.getOrDefault(target, key, null);
89+
if ((query & READABLE) != 0 && accessor.hasGetter()) {
90+
return true;
91+
}
92+
if ((query & MODIFIABLE) != 0 && accessor.hasSetter()) {
93+
return true;
94+
}
95+
if ((query & READ_SIDE_EFFECTS) != 0 && accessor.hasGetter()) {
96+
return true;
97+
}
98+
if ((query & WRITE_SIDE_EFFECTS) != 0 && accessor.hasSetter()) {
99+
return true;
100+
}
101+
if ((query & REMOVABLE) != 0 && JSProperty.isConfigurable(property)) {
102+
return true;
103+
}
104+
return false;
105+
} else {
106+
assert JSProperty.isData(property);
107+
if ((query & READABLE) != 0) {
108+
return true;
109+
}
110+
if ((query & MODIFIABLE) != 0 && JSProperty.isWritable(property)) {
111+
return true;
112+
}
113+
if ((query & INVOCABLE) != 0 && isCallable.executeBoolean(objectLibrary.getOrDefault(target, key, Undefined.instance))) {
114+
return true;
115+
}
116+
if ((query & REMOVABLE) != 0 && JSProperty.isConfigurable(property)) {
117+
return true;
118+
}
119+
return false;
120+
}
121+
}
122+
123+
@Specialization(replaces = "cachedOwnProperty")
124+
static boolean member(DynamicObject target, String key, int query,
125+
@Cached GetPrototypeNode getPrototype,
126+
@Cached IsCallableNode isCallable,
127+
@Cached IsExtensibleNode isExtensible) {
75128
PropertyDescriptor desc = null;
76129
boolean isProxy = false;
77-
for (DynamicObject proto = target; proto != Null.instance; proto = JSObject.getPrototype(proto)) {
130+
for (DynamicObject proto = target; proto != Null.instance; proto = getPrototype.executeJSObject(proto)) {
78131
desc = JSObject.getOwnProperty(proto, key);
79132
if (JSProxy.isJSProxy(proto)) {
80133
isProxy = true;
@@ -85,7 +138,7 @@ static boolean member(DynamicObject target, String key, int query) {
85138
}
86139
}
87140
if (desc == null) {
88-
if ((query & INSERTABLE) != 0 && JSObject.isExtensible(target)) {
141+
if ((query & INSERTABLE) != 0 && isExtensible.executeBoolean(target)) {
89142
return true;
90143
}
91144
return false;
@@ -109,7 +162,7 @@ static boolean member(DynamicObject target, String key, int query) {
109162
if ((query & WRITE_SIDE_EFFECTS) != 0 && writeSideEffects) {
110163
return true;
111164
}
112-
if ((query & INVOCABLE) != 0 && desc.isDataDescriptor() && JSRuntime.isCallable(desc.getValue())) {
165+
if ((query & INVOCABLE) != 0 && desc.isDataDescriptor() && isCallable.executeBoolean(desc.getValue())) {
113166
return true;
114167
}
115168
if ((query & REMOVABLE) != 0 && desc.getConfigurable()) {

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/interop/DynamicScopeWrapper.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ Object getMembers(@SuppressWarnings("unused") boolean includeInternal,
9696
}
9797

9898
@ExportMessage
99-
@TruffleBoundary
10099
boolean isMemberReadable(String name,
101100
@CachedLibrary("this.scope") DynamicObjectLibrary access) {
102101
Object value = access.getOrDefault(scope, name, null);
@@ -107,7 +106,6 @@ boolean isMemberReadable(String name,
107106
}
108107

109108
@ExportMessage
110-
@TruffleBoundary
111109
boolean isMemberModifiable(String name,
112110
@CachedLibrary("this.scope") DynamicObjectLibrary access) {
113111
return isMemberReadable(name, access) && !isConst(name, access);
@@ -120,7 +118,6 @@ boolean isMemberInsertable(@SuppressWarnings("unused") String name) {
120118
}
121119

122120
@ExportMessage
123-
@TruffleBoundary
124121
Object readMember(String name,
125122
@CachedLibrary("this.scope") DynamicObjectLibrary access,
126123
@Cached ExportValueNode exportValueNode) throws UnknownIdentifierException {
@@ -133,7 +130,6 @@ Object readMember(String name,
133130
}
134131

135132
@ExportMessage
136-
@TruffleBoundary
137133
void writeMember(String name, Object value,
138134
@CachedLibrary("this.scope") DynamicObjectLibrary access) throws UnsupportedMessageException, UnknownIdentifierException {
139135
Object curValue = access.getOrDefault(scope, name, null);

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/objects/Accessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
package com.oracle.truffle.js.runtime.objects;
4242

43-
import com.oracle.truffle.api.object.*;
43+
import com.oracle.truffle.api.object.DynamicObject;
4444

4545
public final class Accessor {
4646
private final DynamicObject getter;
@@ -58,4 +58,12 @@ public DynamicObject getGetter() {
5858
public DynamicObject getSetter() {
5959
return setter;
6060
}
61+
62+
public boolean hasGetter() {
63+
return getter != Undefined.instance;
64+
}
65+
66+
public boolean hasSetter() {
67+
return setter != Undefined.instance;
68+
}
6169
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/objects/JSDynamicObject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public static void setJSClass(DynamicObject obj, JSClass jsclass) {
352352
}
353353

354354
public static Object getDynamicType(DynamicObject obj) {
355-
return DynamicObjectLibrary.getUncached().getDynamicType(obj);
355+
return obj.getShape().getDynamicType();
356356
}
357357

358358
public static boolean hasProperty(DynamicObject obj, Object key) {
@@ -388,7 +388,7 @@ public static int getIntOrDefault(DynamicObject obj, Object key, int defaultValu
388388
}
389389

390390
public static int getObjectFlags(DynamicObject obj) {
391-
return DynamicObjectLibrary.getUncached().getShapeFlags(obj);
391+
return obj.getShape().getFlags();
392392
}
393393

394394
public static void setObjectFlags(DynamicObject obj, int flags) {

0 commit comments

Comments
 (0)