Skip to content

Commit a574e41

Browse files
[GR-58584] Don't use context/language references with this of inlined nodes.
PullRequest: graal/18927
2 parents 02b0d1c + 1b65328 commit a574e41

File tree

4 files changed

+85
-36
lines changed

4 files changed

+85
-36
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024, 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.nodes;
24+
25+
import java.util.Objects;
26+
27+
import com.oracle.truffle.api.nodes.Node;
28+
import com.oracle.truffle.api.nodes.NodeInfo;
29+
import com.oracle.truffle.espresso.EspressoLanguage;
30+
import com.oracle.truffle.espresso.meta.Meta;
31+
import com.oracle.truffle.espresso.runtime.EspressoContext;
32+
33+
@NodeInfo(language = EspressoLanguage.NAME, description = "The abstract base node for all inlinable " + EspressoLanguage.IMPLEMENTATION_NAME + " nodes")
34+
public abstract class EspressoInlineNode extends Node {
35+
public static Meta getMeta(Node node) {
36+
Objects.requireNonNull(node);
37+
return EspressoContext.get(node).getMeta();
38+
}
39+
}

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_com_oracle_truffle_espresso_polyglot_Interop.java

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.oracle.truffle.espresso.impl.PrimitiveKlass;
6262
import com.oracle.truffle.espresso.meta.EspressoError;
6363
import com.oracle.truffle.espresso.meta.Meta;
64+
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
6465
import com.oracle.truffle.espresso.nodes.interop.LookupInternalTypeConverterNode;
6566
import com.oracle.truffle.espresso.nodes.interop.LookupTypeConverterNode;
6667
import com.oracle.truffle.espresso.nodes.interop.MethodArgsUtils;
@@ -4275,7 +4276,7 @@ static StaticObject doCached(
42754276
*/
42764277
@GenerateInline
42774278
@GenerateCached(false)
4278-
abstract static class ToHostArguments extends SubstitutionNode {
4279+
abstract static class ToHostArguments extends EspressoInlineNode {
42794280
private static final Object[] EMPTY_ARRAY = new Object[0];
42804281

42814282
abstract Object[] execute(Node node, boolean unwrapArguments, @JavaType(Object[].class) StaticObject arguments);
@@ -4284,48 +4285,53 @@ abstract static class ToHostArguments extends SubstitutionNode {
42844285
"!unwrapArguments",
42854286
"arguments.isEspressoObject()"
42864287
})
4287-
Object[] doEspressoNoUnwrap(
4288+
static Object[] doEspressoNoUnwrap(
42884289
@SuppressWarnings("unused") boolean unwrapArguments,
4289-
@JavaType(Object[].class) StaticObject arguments) {
4290-
return arguments.<StaticObject[]> unwrap(getLanguage());
4290+
@JavaType(Object[].class) StaticObject arguments,
4291+
@Bind("$node") Node node) {
4292+
return arguments.<StaticObject[]> unwrap(EspressoLanguage.get(node));
42914293
}
42924294

42934295
@Specialization(guards = {
42944296
"unwrapArguments",
42954297
"arguments.isEspressoObject()",
42964298
})
4297-
Object[] doEspressoUnwrap(
4299+
static Object[] doEspressoUnwrap(
42984300
@SuppressWarnings("unused") boolean unwrapArguments,
4299-
@JavaType(Object[].class) StaticObject arguments) {
4300-
EspressoLanguage language = getLanguage();
4301+
@JavaType(Object[].class) StaticObject arguments,
4302+
@Bind("$node") Node node) {
4303+
EspressoLanguage language = EspressoLanguage.get(node);
43014304
Object[] rawArgs = arguments.unwrap(language);
43024305
if (rawArgs.length == 0) {
43034306
return EMPTY_ARRAY;
43044307
}
43054308
Object[] hostArgs = new Object[rawArgs.length];
4309+
Meta meta = EspressoContext.get(node).getMeta();
43064310
for (int i = 0; i < rawArgs.length; ++i) {
4307-
hostArgs[i] = InteropUtils.unwrap(language, (StaticObject) rawArgs[i], getMeta());
4311+
hostArgs[i] = InteropUtils.unwrap(language, (StaticObject) rawArgs[i], meta);
43084312
}
43094313
return hostArgs;
43104314
}
43114315

43124316
@Specialization(guards = {
43134317
"arguments.isForeignObject()",
43144318
})
4315-
Object[] doForeign(
4319+
static Object[] doForeign(
43164320
boolean unwrapArguments,
43174321
@JavaType(Object[].class) StaticObject arguments,
43184322
@Cached(inline = false) GetArraySize getArraySize,
4319-
@Cached(inline = false) ReadArrayElement readArrayElement) {
4320-
EspressoLanguage language = getLanguage();
4323+
@Cached(inline = false) ReadArrayElement readArrayElement,
4324+
@Bind("$node") Node node) {
4325+
EspressoLanguage language = EspressoLanguage.get(node);
43214326
int argsLength = Math.toIntExact(getArraySize.execute(arguments));
43224327
if (argsLength == 0) {
43234328
return EMPTY_ARRAY;
43244329
}
43254330
Object[] hostArgs = new Object[argsLength];
4331+
Meta meta = EspressoContext.get(node).getMeta();
43264332
for (int i = 0; i < argsLength; ++i) {
43274333
StaticObject elem = readArrayElement.execute(arguments, i);
4328-
hostArgs[i] = unwrapArguments ? InteropUtils.unwrap(language, elem, getMeta()) : elem;
4334+
hostArgs[i] = unwrapArguments ? InteropUtils.unwrap(language, elem, meta) : elem;
43294335
}
43304336
return hostArgs;
43314337
}
@@ -4336,7 +4342,7 @@ Object[] doForeign(
43364342
*/
43374343
@GenerateInline
43384344
@GenerateCached(false)
4339-
abstract static class ThrowInteropExceptionAsGuest extends SubstitutionNode {
4345+
abstract static class ThrowInteropExceptionAsGuest extends EspressoInlineNode {
43404346
static final int LIMIT = 2;
43414347

43424348
abstract RuntimeException execute(Node node, InteropException hostException);
@@ -4347,8 +4353,8 @@ static RuntimeException doUnsupportedMessageException(
43474353
UnsupportedMessageException e,
43484354
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
43494355
@Cached @Shared InlinedConditionProfile noCauseProfile,
4350-
@Cached(value = "create(getMeta().polyglot.UnsupportedMessageException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
4351-
@Cached(value = "create(getMeta().polyglot.UnsupportedMessageException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
4356+
@Cached(value = "create(getMeta(node).polyglot.UnsupportedMessageException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
4357+
@Cached(value = "create(getMeta(node).polyglot.UnsupportedMessageException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
43524358
Throwable cause = e.getCause();
43534359
assert cause == null || cause instanceof AbstractTruffleException;
43544360
EspressoContext context = EspressoContext.get(node);
@@ -4367,8 +4373,8 @@ static RuntimeException doUnknownIdentifierException(
43674373
UnknownIdentifierException e,
43684374
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
43694375
@Cached @Shared InlinedConditionProfile noCauseProfile,
4370-
@Cached(value = "create(getMeta().polyglot.UnknownIdentifierException_create_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifier,
4371-
@Cached(value = "create(getMeta().polyglot.UnknownIdentifierException_create_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifierAndCause) {
4376+
@Cached(value = "create(getMeta(node).polyglot.UnknownIdentifierException_create_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifier,
4377+
@Cached(value = "create(getMeta(node).polyglot.UnknownIdentifierException_create_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifierAndCause) {
43724378
EspressoContext context = EspressoContext.get(node);
43734379
Meta meta = context.getMeta();
43744380
StaticObject unknownIdentifier = meta.toGuestString(e.getUnknownIdentifier());
@@ -4390,8 +4396,8 @@ static RuntimeException doArityException(
43904396
ArityException e,
43914397
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
43924398
@Cached @Shared InlinedConditionProfile noCauseProfile,
4393-
@Cached(value = "create(getMeta().polyglot.ArityException_create_int_int_int.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRange,
4394-
@Cached(value = "create(getMeta().polyglot.ArityException_create_int_int_int_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRangeAndCause) {
4399+
@Cached(value = "create(getMeta(node).polyglot.ArityException_create_int_int_int.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRange,
4400+
@Cached(value = "create(getMeta(node).polyglot.ArityException_create_int_int_int_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRangeAndCause) {
43954401
int expectedMinArity = e.getExpectedMinArity();
43964402
int expectedMaxArity = e.getExpectedMaxArity();
43974403
int actualArity = e.getActualArity();
@@ -4419,8 +4425,8 @@ static RuntimeException doUnsupportedTypeException(
44194425
UnsupportedTypeException e,
44204426
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
44214427
@Cached @Shared InlinedConditionProfile noCauseProfile,
4422-
@Cached(value = "create(getMeta().polyglot.UnsupportedTypeException_create_Object_array_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHint,
4423-
@Cached(value = "create(getMeta().polyglot.UnsupportedTypeException_create_Object_array_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHintAndCause) {
4428+
@Cached(value = "create(getMeta(node).polyglot.UnsupportedTypeException_create_Object_array_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHint,
4429+
@Cached(value = "create(getMeta(node).polyglot.UnsupportedTypeException_create_Object_array_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHintAndCause) {
44244430
Object[] hostValues = e.getSuppliedValues();
44254431
EspressoContext context = EspressoContext.get(node);
44264432
Meta meta = context.getMeta();
@@ -4451,8 +4457,8 @@ static RuntimeException doInvalidArrayIndexException(
44514457
InvalidArrayIndexException e,
44524458
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
44534459
@Cached @Shared InlinedConditionProfile noCauseProfile,
4454-
@Cached(value = "create(getMeta().polyglot.InvalidArrayIndexException_create_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndex,
4455-
@Cached(value = "create(getMeta().polyglot.InvalidArrayIndexException_create_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndexAndCause) {
4460+
@Cached(value = "create(getMeta(node).polyglot.InvalidArrayIndexException_create_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndex,
4461+
@Cached(value = "create(getMeta(node).polyglot.InvalidArrayIndexException_create_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndexAndCause) {
44564462
long invalidIndex = e.getInvalidIndex();
44574463
Throwable cause = e.getCause();
44584464
EspressoContext context = EspressoContext.get(node);
@@ -4473,8 +4479,8 @@ static RuntimeException doInvalidBufferOffsetException(
44734479
InvalidBufferOffsetException e,
44744480
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
44754481
@Cached @Shared InlinedConditionProfile noCauseProfile,
4476-
@Cached(value = "create(getMeta().polyglot.InvalidBufferOffsetException_create_long_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLength,
4477-
@Cached(value = "create(getMeta().polyglot.InvalidBufferOffsetException_create_long_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLengthAndCause) {
4482+
@Cached(value = "create(getMeta(node).polyglot.InvalidBufferOffsetException_create_long_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLength,
4483+
@Cached(value = "create(getMeta(node).polyglot.InvalidBufferOffsetException_create_long_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLengthAndCause) {
44784484
long byteOffset = e.getByteOffset();
44794485
long length = e.getLength();
44804486
Throwable cause = e.getCause();
@@ -4497,8 +4503,8 @@ static RuntimeException doStopIterationException(
44974503
StopIterationException e,
44984504
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
44994505
@Cached @Shared InlinedConditionProfile noCauseProfile,
4500-
@Cached(value = "create(getMeta().polyglot.StopIterationException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
4501-
@Cached(value = "create(getMeta().polyglot.StopIterationException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
4506+
@Cached(value = "create(getMeta(node).polyglot.StopIterationException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
4507+
@Cached(value = "create(getMeta(node).polyglot.StopIterationException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
45024508
Throwable cause = e.getCause();
45034509
EspressoContext context = EspressoContext.get(node);
45044510
Meta meta = context.getMeta();
@@ -4517,8 +4523,8 @@ static RuntimeException doUnknownKeyException(
45174523
@CachedLibrary(limit = "LIMIT") @Exclusive InteropLibrary keyInterop,
45184524
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
45194525
@Cached @Shared InlinedConditionProfile noCauseProfile,
4520-
@Cached(value = "create(getMeta().polyglot.UnknownKeyException_create_Object.getCallTargetForceInit())", inline = false) DirectCallNode createWithKey,
4521-
@Cached(value = "create(getMeta().polyglot.UnknownKeyException_create_Object_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithKeyAndCause) {
4526+
@Cached(value = "create(getMeta(node).polyglot.UnknownKeyException_create_Object.getCallTargetForceInit())", inline = false) DirectCallNode createWithKey,
4527+
@Cached(value = "create(getMeta(node).polyglot.UnknownKeyException_create_Object_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithKeyAndCause) {
45224528
EspressoContext context = EspressoContext.get(node);
45234529
Meta meta = context.getMeta();
45244530
StaticObject unknownKey = InteropUtils.maybeWrapAsObject(e.getUnknownKey(), keyInterop, context);

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_java_util_regex_Matcher.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import com.oracle.truffle.espresso.impl.ObjectKlass;
5757
import com.oracle.truffle.espresso.meta.EspressoError;
5858
import com.oracle.truffle.espresso.meta.Meta;
59+
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
5960
import com.oracle.truffle.espresso.nodes.bytecodes.InvokeInterface;
6061
import com.oracle.truffle.espresso.runtime.EspressoContext;
6162
import com.oracle.truffle.espresso.runtime.JavaVersion;
@@ -332,7 +333,7 @@ static int doDefault(StaticObject self,
332333

333334
@GenerateInline
334335
@GenerateUncached
335-
abstract static class JavaRegexCompileNode extends Node {
336+
abstract static class JavaRegexCompileNode extends EspressoInlineNode {
336337
public abstract Object execute(Node node, StaticObject self, RegexAction action, Field destination, EspressoContext context);
337338

338339
@Specialization
@@ -458,7 +459,7 @@ private static int getGroupCount(Object regexObject, InteropLibrary regexObjectI
458459

459460
@GenerateInline
460461
@GenerateUncached
461-
public abstract static class JavaRegexExecNode extends Node {
462+
public abstract static class JavaRegexExecNode extends EspressoInlineNode {
462463
public abstract boolean execute(Node node, Object regexObject, StaticObject self, int from, Meta meta);
463464

464465
@Specialization

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/substitutions/Target_sun_misc_Unsafe.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
import com.oracle.truffle.espresso.meta.JavaKind;
6161
import com.oracle.truffle.espresso.meta.Meta;
6262
import com.oracle.truffle.espresso.meta.MetaUtil;
63-
import com.oracle.truffle.espresso.nodes.EspressoNode;
63+
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
6464
import com.oracle.truffle.espresso.runtime.EspressoContext;
6565
import com.oracle.truffle.espresso.runtime.EspressoException;
6666
import com.oracle.truffle.espresso.runtime.GuestAllocator;
@@ -905,23 +905,26 @@ public static long objectFieldOffset1(@JavaType(Unsafe.class) StaticObject self,
905905

906906
@GenerateInline
907907
@GenerateCached(false)
908-
abstract static class GetFieldFromIndexNode extends EspressoNode {
908+
abstract static class GetFieldFromIndexNode extends EspressoInlineNode {
909909
static final int LIMIT = 3;
910910

911911
abstract Field execute(Node node, StaticObject holder, long slot);
912912

913913
@Specialization(guards = {"slot == cachedSlot", "holder.isStaticStorage() == cachedIsStaticStorage", "holder.getKlass() == cachedKlass"}, limit = "LIMIT")
914914
static Field doCached(@SuppressWarnings("unused") StaticObject holder, @SuppressWarnings("unused") long slot,
915+
@SuppressWarnings("unused") @Bind("$node") Node node,
915916
@SuppressWarnings("unused") @Cached("slot") long cachedSlot,
916917
@SuppressWarnings("unused") @Cached("holder.getKlass()") Klass cachedKlass,
917918
@SuppressWarnings("unused") @Cached("holder.isStaticStorage()") boolean cachedIsStaticStorage,
918-
@Cached("doGeneric(holder, slot)") Field cachedField) {
919+
@Cached("doGeneric(holder, slot, node)") Field cachedField) {
919920
return cachedField;
920921
}
921922

922923
@Specialization(replaces = "doCached")
923-
Field doGeneric(StaticObject holder, long slot) {
924-
return resolveUnsafeAccessField(holder, slot, getMeta(), getLanguage());
924+
static Field doGeneric(StaticObject holder, long slot,
925+
@Bind("$node") Node node) {
926+
Meta meta = EspressoContext.get(node).getMeta();
927+
return resolveUnsafeAccessField(holder, slot, meta, EspressoLanguage.get(node));
925928
}
926929
}
927930

0 commit comments

Comments
 (0)