Skip to content

Commit d69709e

Browse files
committed
[GR-37170] Cleanups. Use VarHandle for atomic updates. Migrate getCallerFrame().
PullRequest: js/2350
2 parents ec98665 + 01ae40f commit d69709e

25 files changed

+266
-335
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{
2525
"name" : "regex",
2626
"subdir" : True,
27-
"version" : "6bb3cd3bc19177862d8482ea5f801c6f2356c93d",
27+
"version" : "e951a56d562a42aa5fa39f50f8b8225ddf70818c",
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"},

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public abstract static class JSBindNode extends JSBuiltinNode {
194194
private final ConditionProfile setNameProfile = ConditionProfile.createBinaryProfile();
195195
private final ConditionProfile hasFunctionLengthProfile = ConditionProfile.createBinaryProfile();
196196
private final ConditionProfile hasIntegerFunctionLengthProfile = ConditionProfile.createBinaryProfile();
197+
private final ConditionProfile isConstructorProfile = ConditionProfile.createBinaryProfile();
197198
private final ConditionProfile isAsyncProfile = ConditionProfile.createBinaryProfile();
198199
private final ConditionProfile setProtoProfile = ConditionProfile.createBinaryProfile();
199200

@@ -210,7 +211,8 @@ public JSBindNode(JSContext context, JSBuiltin builtin) {
210211
protected DynamicObject bindFunction(DynamicObject thisFnObj, Object thisArg, Object[] args) {
211212
DynamicObject proto = getPrototypeNode.execute(thisFnObj);
212213

213-
DynamicObject boundFunction = JSFunction.boundFunctionCreate(getContext(), thisFnObj, thisArg, args, proto, isAsyncProfile, setProtoProfile, this);
214+
DynamicObject boundFunction = JSFunction.boundFunctionCreate(getContext(), thisFnObj, thisArg, args, proto,
215+
isConstructorProfile, isAsyncProfile, setProtoProfile, this);
214216

215217
Number length = 0;
216218
boolean mustSetLength = true;
@@ -264,7 +266,8 @@ protected DynamicObject bindProxy(DynamicObject thisObj, Object thisArg, Object[
264266
}
265267
assert JSFunction.isJSFunction(innerFunction);
266268

267-
DynamicObject boundFunction = JSFunction.boundFunctionCreate(getContext(), (DynamicObject) innerFunction, thisArg, args, proto, isAsyncProfile, setProtoProfile, this);
269+
DynamicObject boundFunction = JSFunction.boundFunctionCreate(getContext(), (DynamicObject) innerFunction, thisArg, args, proto,
270+
isConstructorProfile, isAsyncProfile, setProtoProfile, this);
268271

269272
Number length = 0;
270273
boolean targetHasLength = JSObject.hasOwnProperty(thisObj, JSFunction.LENGTH);

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@
5555
import java.util.EnumSet;
5656
import java.util.StringTokenizer;
5757

58-
import com.oracle.truffle.api.CallTarget;
5958
import com.oracle.truffle.api.CompilerAsserts;
6059
import com.oracle.truffle.api.CompilerDirectives;
6160
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
62-
import com.oracle.truffle.api.RootCallTarget;
63-
import com.oracle.truffle.api.Truffle;
6461
import com.oracle.truffle.api.TruffleFile;
6562
import com.oracle.truffle.api.TruffleLanguage;
6663
import com.oracle.truffle.api.dsl.Cached;
@@ -81,7 +78,6 @@
8178
import com.oracle.truffle.api.profiles.BranchProfile;
8279
import com.oracle.truffle.api.profiles.ConditionProfile;
8380
import com.oracle.truffle.api.source.Source;
84-
import com.oracle.truffle.api.source.SourceSection;
8581
import com.oracle.truffle.api.strings.TruffleString;
8682
import com.oracle.truffle.api.strings.TruffleStringBuilder;
8783
import com.oracle.truffle.js.builtins.GlobalBuiltinsFactory.GlobalNashornExtensionParseToJSONNodeGen;
@@ -567,18 +563,15 @@ public static TruffleFile resolveRelativeFilePath(String path, TruffleLanguage.E
567563

568564
private static TruffleFile tryResolveCallerRelativeFilePath(String path, TruffleLanguage.Env env) {
569565
CompilerAsserts.neverPartOfCompilation();
570-
CallTarget caller = Truffle.getRuntime().getCallerFrame().getCallTarget();
571-
if (caller instanceof RootCallTarget) {
572-
SourceSection callerSourceSection = ((RootCallTarget) caller).getRootNode().getSourceSection();
573-
if (callerSourceSection != null && callerSourceSection.isAvailable()) {
574-
String callerPath = callerSourceSection.getSource().getPath();
575-
if (callerPath != null) {
576-
TruffleFile callerFile = env.getPublicTruffleFile(callerPath);
577-
if (callerFile.isAbsolute()) {
578-
TruffleFile file = callerFile.resolveSibling(path).normalize();
579-
if (file.isRegularFile()) {
580-
return file;
581-
}
566+
Source callerSource = JSFunction.getCallerSource();
567+
if (callerSource != null) {
568+
String callerPath = callerSource.getPath();
569+
if (callerPath != null) {
570+
TruffleFile callerFile = env.getPublicTruffleFile(callerPath);
571+
if (callerFile.isAbsolute()) {
572+
TruffleFile file = callerFile.resolveSibling(path).normalize();
573+
if (file.isRegularFile()) {
574+
return file;
582575
}
583576
}
584577
}
@@ -1706,7 +1699,7 @@ private void doImport(Object globalContextBindings) {
17061699
}
17071700
}
17081701

1709-
private static class ScriptEngineGlobalScopeBindingsPropertyProxy implements PropertyProxy {
1702+
private static final class ScriptEngineGlobalScopeBindingsPropertyProxy extends PropertyProxy {
17101703

17111704
private final TruffleString key;
17121705
private final Object globalContextBindings;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ private static String beanAccessor(String prefix, String beanProperty) {
13551355
return prefix + Character.toUpperCase(beanProperty.charAt(0)) + beanProperty.substring(1);
13561356
}
13571357

1358-
static class BoundProperty implements PropertyProxy {
1358+
static final class BoundProperty extends PropertyProxy {
13591359
private final DynamicObject source;
13601360
private final Object key;
13611361
private final JSClass sourceClass;
@@ -1378,7 +1378,7 @@ public boolean set(DynamicObject store, Object value) {
13781378

13791379
}
13801380

1381-
static class ForeignBoundProperty implements PropertyProxy {
1381+
static final class ForeignBoundProperty extends PropertyProxy {
13821382
private final Object source;
13831383
private final String key;
13841384

@@ -1413,7 +1413,7 @@ public boolean set(DynamicObject store, Object value) {
14131413
}
14141414
}
14151415

1416-
static class ForeignBoundBeanProperty implements PropertyProxy {
1416+
static final class ForeignBoundBeanProperty extends PropertyProxy {
14171417
private final Object source;
14181418
private final String getKey;
14191419
private final String setKey;

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/builtins/commonjs/CommonJSResolution.java

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,10 @@
4848
import java.util.stream.IntStream;
4949

5050
import com.oracle.truffle.api.CompilerDirectives;
51-
import com.oracle.truffle.api.Truffle;
5251
import com.oracle.truffle.api.TruffleFile;
5352
import com.oracle.truffle.api.TruffleLanguage;
54-
import com.oracle.truffle.api.frame.FrameInstance;
55-
import com.oracle.truffle.api.nodes.RootNode;
5653
import com.oracle.truffle.api.object.DynamicObject;
5754
import com.oracle.truffle.api.source.Source;
58-
import com.oracle.truffle.api.source.SourceSection;
5955
import com.oracle.truffle.api.strings.TruffleString;
6056
import com.oracle.truffle.js.builtins.GlobalBuiltins;
6157
import com.oracle.truffle.js.lang.JavaScriptLanguage;
@@ -133,21 +129,9 @@ static boolean isCoreModule(TruffleString moduleIdentifier) {
133129
}
134130

135131
static String getCurrentFileNameFromStack() {
136-
FrameInstance callerFrame = Truffle.getRuntime().getCallerFrame();
137-
if (callerFrame != null) {
138-
SourceSection encapsulatingSourceSection = null;
139-
if (callerFrame.getCallNode() != null) {
140-
encapsulatingSourceSection = callerFrame.getCallNode().getEncapsulatingSourceSection();
141-
} else {
142-
RootNode frameRootNode = JSFunction.getFrameRootNode(callerFrame);
143-
if (frameRootNode != null) {
144-
encapsulatingSourceSection = frameRootNode.getEncapsulatingSourceSection();
145-
}
146-
}
147-
if (encapsulatingSourceSection != null && encapsulatingSourceSection.getSource() != null) {
148-
Source source = encapsulatingSourceSection.getSource();
149-
return source.getPath();
150-
}
132+
Source callerSource = JSFunction.getCallerSource();
133+
if (callerSource != null) {
134+
return callerSource.getPath();
151135
}
152136
return null;
153137
}

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/nodes/JavaScriptNode.java

Lines changed: 4 additions & 0 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.CompilerAsserts;
46+
import com.oracle.truffle.api.CompilerDirectives;
4647
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
4748
import com.oracle.truffle.api.dsl.Cached;
4849
import com.oracle.truffle.api.frame.Frame;
@@ -127,6 +128,7 @@ public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
127128
if (o instanceof Integer) {
128129
return (int) o;
129130
} else {
131+
CompilerDirectives.transferToInterpreterAndInvalidate();
130132
throw new UnexpectedResultException(o);
131133
}
132134
}
@@ -146,6 +148,7 @@ public double executeDouble(VirtualFrame frame) throws UnexpectedResultException
146148
if (o instanceof Double) {
147149
return (double) o;
148150
} else {
151+
CompilerDirectives.transferToInterpreterAndInvalidate();
149152
throw new UnexpectedResultException(o);
150153
}
151154
}
@@ -165,6 +168,7 @@ public boolean executeBoolean(VirtualFrame frame) throws UnexpectedResultExcepti
165168
if (o instanceof Boolean) {
166169
return (boolean) o;
167170
} else {
171+
CompilerDirectives.transferToInterpreterAndInvalidate();
168172
throw new UnexpectedResultException(o);
169173
}
170174
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ private DynamicObject executeZeroBasedIntArray(VirtualFrame frame) {
321321
try {
322322
primitiveArray[i] = getElement(i).executeInt(frame);
323323
} catch (UnexpectedResultException e) {
324+
CompilerDirectives.transferToInterpreterAndInvalidate();
324325
assert !(e.getResult() instanceof Integer);
325326
return executeIntArrayFallback(frame, primitiveArray, i, e.getResult());
326327
}
@@ -357,6 +358,7 @@ private DynamicObject executeZeroBasedDoubleArray(VirtualFrame frame) {
357358
}
358359
primitiveArray[i] = doubleValue;
359360
} catch (UnexpectedResultException e) {
361+
CompilerDirectives.transferToInterpreterAndInvalidate();
360362
assert !(e.getResult() instanceof Double);
361363
if (e.getResult() instanceof Integer) {
362364
primitiveArray[i] = (int) e.getResult();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -54,7 +54,6 @@
5454
import com.oracle.truffle.js.runtime.objects.JSDynamicObject;
5555
import com.oracle.truffle.js.runtime.objects.JSProperty;
5656
import com.oracle.truffle.js.runtime.objects.JSShape;
57-
import com.oracle.truffle.js.runtime.util.AssumptionUtil;
5857

5958
/**
6059
* Checks if a scope binding is present and guards against TDZ and const assignment.
@@ -138,6 +137,6 @@ final Assumption getAbsentPropertyAssumption(Shape shape) {
138137
if (property == null) {
139138
return JSShape.getPropertyAssumption(shape, varName);
140139
}
141-
return AssumptionUtil.neverValidAssumption();
140+
return Assumption.NEVER_VALID;
142141
}
143142
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2022, 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
@@ -40,6 +40,7 @@
4040
*/
4141
package com.oracle.truffle.js.nodes.access;
4242

43+
import com.oracle.truffle.api.CompilerDirectives;
4344
import com.oracle.truffle.api.frame.VirtualFrame;
4445
import com.oracle.truffle.api.instrumentation.GenerateWrapper;
4546
import com.oracle.truffle.api.instrumentation.ProbeNode;
@@ -62,6 +63,7 @@ public int executeIntWithTarget(VirtualFrame frame, Object target) throws Unexpe
6263
if (o instanceof Integer) {
6364
return (int) o;
6465
} else {
66+
CompilerDirectives.transferToInterpreterAndInvalidate();
6567
throw new UnexpectedResultException(o);
6668
}
6769
}
@@ -73,6 +75,7 @@ public double executeDoubleWithTarget(VirtualFrame frame, Object target) throws
7375
} else if (o instanceof Integer) {
7476
return (int) o;
7577
} else {
78+
CompilerDirectives.transferToInterpreterAndInvalidate();
7679
throw new UnexpectedResultException(o);
7780
}
7881
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022, 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 java.util.Set;
4444

45+
import com.oracle.truffle.api.CompilerDirectives;
4546
import com.oracle.truffle.api.frame.VirtualFrame;
4647
import com.oracle.truffle.api.instrumentation.Tag;
4748
import com.oracle.truffle.api.nodes.ControlFlowException;
@@ -103,6 +104,7 @@ public int executeInt(VirtualFrame frame) throws UnexpectedResultException {
103104
try {
104105
return accessNode.executeInt(frame);
105106
} catch (ShortCircuitException ex) {
107+
CompilerDirectives.transferToInterpreterAndInvalidate();
106108
throw new UnexpectedResultException(result);
107109
}
108110
}
@@ -112,6 +114,7 @@ public double executeDouble(VirtualFrame frame) throws UnexpectedResultException
112114
try {
113115
return accessNode.executeDouble(frame);
114116
} catch (ShortCircuitException ex) {
117+
CompilerDirectives.transferToInterpreterAndInvalidate();
115118
throw new UnexpectedResultException(result);
116119
}
117120
}

0 commit comments

Comments
 (0)