Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-58584] Don't use context/language references with this of inlined nodes. #9841

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.truffle.espresso.nodes;

import java.util.Objects;

import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.NodeInfo;
import com.oracle.truffle.espresso.EspressoLanguage;
import com.oracle.truffle.espresso.meta.Meta;
import com.oracle.truffle.espresso.runtime.EspressoContext;

@NodeInfo(language = EspressoLanguage.NAME, description = "The abstract base node for all inlinable " + EspressoLanguage.IMPLEMENTATION_NAME + " nodes")
public abstract class EspressoInlineNode extends Node {
public static Meta getMeta(Node node) {
Objects.requireNonNull(node);
return EspressoContext.get(node).getMeta();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.oracle.truffle.espresso.impl.PrimitiveKlass;
import com.oracle.truffle.espresso.meta.EspressoError;
import com.oracle.truffle.espresso.meta.Meta;
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
import com.oracle.truffle.espresso.nodes.interop.LookupInternalTypeConverterNode;
import com.oracle.truffle.espresso.nodes.interop.LookupTypeConverterNode;
import com.oracle.truffle.espresso.nodes.interop.MethodArgsUtils;
Expand Down Expand Up @@ -4275,7 +4276,7 @@ static StaticObject doCached(
*/
@GenerateInline
@GenerateCached(false)
abstract static class ToHostArguments extends SubstitutionNode {
abstract static class ToHostArguments extends EspressoInlineNode {
private static final Object[] EMPTY_ARRAY = new Object[0];

abstract Object[] execute(Node node, boolean unwrapArguments, @JavaType(Object[].class) StaticObject arguments);
Expand All @@ -4284,48 +4285,53 @@ abstract static class ToHostArguments extends SubstitutionNode {
"!unwrapArguments",
"arguments.isEspressoObject()"
})
Object[] doEspressoNoUnwrap(
static Object[] doEspressoNoUnwrap(
@SuppressWarnings("unused") boolean unwrapArguments,
@JavaType(Object[].class) StaticObject arguments) {
return arguments.<StaticObject[]> unwrap(getLanguage());
@JavaType(Object[].class) StaticObject arguments,
@Bind("$node") Node node) {
return arguments.<StaticObject[]> unwrap(EspressoLanguage.get(node));
}

@Specialization(guards = {
"unwrapArguments",
"arguments.isEspressoObject()",
})
Object[] doEspressoUnwrap(
static Object[] doEspressoUnwrap(
@SuppressWarnings("unused") boolean unwrapArguments,
@JavaType(Object[].class) StaticObject arguments) {
EspressoLanguage language = getLanguage();
@JavaType(Object[].class) StaticObject arguments,
@Bind("$node") Node node) {
EspressoLanguage language = EspressoLanguage.get(node);
Object[] rawArgs = arguments.unwrap(language);
if (rawArgs.length == 0) {
return EMPTY_ARRAY;
}
Object[] hostArgs = new Object[rawArgs.length];
Meta meta = EspressoContext.get(node).getMeta();
for (int i = 0; i < rawArgs.length; ++i) {
hostArgs[i] = InteropUtils.unwrap(language, (StaticObject) rawArgs[i], getMeta());
hostArgs[i] = InteropUtils.unwrap(language, (StaticObject) rawArgs[i], meta);
}
return hostArgs;
}

@Specialization(guards = {
"arguments.isForeignObject()",
})
Object[] doForeign(
static Object[] doForeign(
boolean unwrapArguments,
@JavaType(Object[].class) StaticObject arguments,
@Cached(inline = false) GetArraySize getArraySize,
@Cached(inline = false) ReadArrayElement readArrayElement) {
EspressoLanguage language = getLanguage();
@Cached(inline = false) ReadArrayElement readArrayElement,
@Bind("$node") Node node) {
EspressoLanguage language = EspressoLanguage.get(node);
int argsLength = Math.toIntExact(getArraySize.execute(arguments));
if (argsLength == 0) {
return EMPTY_ARRAY;
}
Object[] hostArgs = new Object[argsLength];
Meta meta = EspressoContext.get(node).getMeta();
for (int i = 0; i < argsLength; ++i) {
StaticObject elem = readArrayElement.execute(arguments, i);
hostArgs[i] = unwrapArguments ? InteropUtils.unwrap(language, elem, getMeta()) : elem;
hostArgs[i] = unwrapArguments ? InteropUtils.unwrap(language, elem, meta) : elem;
}
return hostArgs;
}
Expand All @@ -4336,7 +4342,7 @@ Object[] doForeign(
*/
@GenerateInline
@GenerateCached(false)
abstract static class ThrowInteropExceptionAsGuest extends SubstitutionNode {
abstract static class ThrowInteropExceptionAsGuest extends EspressoInlineNode {
static final int LIMIT = 2;

abstract RuntimeException execute(Node node, InteropException hostException);
Expand All @@ -4347,8 +4353,8 @@ static RuntimeException doUnsupportedMessageException(
UnsupportedMessageException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.UnsupportedMessageException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
@Cached(value = "create(getMeta().polyglot.UnsupportedMessageException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
@Cached(value = "create(getMeta(node).polyglot.UnsupportedMessageException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
@Cached(value = "create(getMeta(node).polyglot.UnsupportedMessageException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
Throwable cause = e.getCause();
assert cause == null || cause instanceof AbstractTruffleException;
EspressoContext context = EspressoContext.get(node);
Expand All @@ -4367,8 +4373,8 @@ static RuntimeException doUnknownIdentifierException(
UnknownIdentifierException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.UnknownIdentifierException_create_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifier,
@Cached(value = "create(getMeta().polyglot.UnknownIdentifierException_create_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifierAndCause) {
@Cached(value = "create(getMeta(node).polyglot.UnknownIdentifierException_create_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifier,
@Cached(value = "create(getMeta(node).polyglot.UnknownIdentifierException_create_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIdentifierAndCause) {
EspressoContext context = EspressoContext.get(node);
Meta meta = context.getMeta();
StaticObject unknownIdentifier = meta.toGuestString(e.getUnknownIdentifier());
Expand All @@ -4390,8 +4396,8 @@ static RuntimeException doArityException(
ArityException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.ArityException_create_int_int_int.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRange,
@Cached(value = "create(getMeta().polyglot.ArityException_create_int_int_int_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRangeAndCause) {
@Cached(value = "create(getMeta(node).polyglot.ArityException_create_int_int_int.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRange,
@Cached(value = "create(getMeta(node).polyglot.ArityException_create_int_int_int_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithArityRangeAndCause) {
int expectedMinArity = e.getExpectedMinArity();
int expectedMaxArity = e.getExpectedMaxArity();
int actualArity = e.getActualArity();
Expand Down Expand Up @@ -4419,8 +4425,8 @@ static RuntimeException doUnsupportedTypeException(
UnsupportedTypeException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.UnsupportedTypeException_create_Object_array_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHint,
@Cached(value = "create(getMeta().polyglot.UnsupportedTypeException_create_Object_array_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHintAndCause) {
@Cached(value = "create(getMeta(node).polyglot.UnsupportedTypeException_create_Object_array_String.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHint,
@Cached(value = "create(getMeta(node).polyglot.UnsupportedTypeException_create_Object_array_String_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithValuesHintAndCause) {
Object[] hostValues = e.getSuppliedValues();
EspressoContext context = EspressoContext.get(node);
Meta meta = context.getMeta();
Expand Down Expand Up @@ -4451,8 +4457,8 @@ static RuntimeException doInvalidArrayIndexException(
InvalidArrayIndexException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.InvalidArrayIndexException_create_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndex,
@Cached(value = "create(getMeta().polyglot.InvalidArrayIndexException_create_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndexAndCause) {
@Cached(value = "create(getMeta(node).polyglot.InvalidArrayIndexException_create_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndex,
@Cached(value = "create(getMeta(node).polyglot.InvalidArrayIndexException_create_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithIndexAndCause) {
long invalidIndex = e.getInvalidIndex();
Throwable cause = e.getCause();
EspressoContext context = EspressoContext.get(node);
Expand All @@ -4473,8 +4479,8 @@ static RuntimeException doInvalidBufferOffsetException(
InvalidBufferOffsetException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.InvalidBufferOffsetException_create_long_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLength,
@Cached(value = "create(getMeta().polyglot.InvalidBufferOffsetException_create_long_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLengthAndCause) {
@Cached(value = "create(getMeta(node).polyglot.InvalidBufferOffsetException_create_long_long.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLength,
@Cached(value = "create(getMeta(node).polyglot.InvalidBufferOffsetException_create_long_long_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithOffsetLengthAndCause) {
long byteOffset = e.getByteOffset();
long length = e.getLength();
Throwable cause = e.getCause();
Expand All @@ -4497,8 +4503,8 @@ static RuntimeException doStopIterationException(
StopIterationException e,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.StopIterationException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
@Cached(value = "create(getMeta().polyglot.StopIterationException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
@Cached(value = "create(getMeta(node).polyglot.StopIterationException_create.getCallTargetForceInit())", inline = false) DirectCallNode create,
@Cached(value = "create(getMeta(node).polyglot.StopIterationException_create_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithCause) {
Throwable cause = e.getCause();
EspressoContext context = EspressoContext.get(node);
Meta meta = context.getMeta();
Expand All @@ -4517,8 +4523,8 @@ static RuntimeException doUnknownKeyException(
@CachedLibrary(limit = "LIMIT") @Exclusive InteropLibrary keyInterop,
@CachedLibrary(limit = "LIMIT") @Shared InteropLibrary causeInterop,
@Cached @Shared InlinedConditionProfile noCauseProfile,
@Cached(value = "create(getMeta().polyglot.UnknownKeyException_create_Object.getCallTargetForceInit())", inline = false) DirectCallNode createWithKey,
@Cached(value = "create(getMeta().polyglot.UnknownKeyException_create_Object_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithKeyAndCause) {
@Cached(value = "create(getMeta(node).polyglot.UnknownKeyException_create_Object.getCallTargetForceInit())", inline = false) DirectCallNode createWithKey,
@Cached(value = "create(getMeta(node).polyglot.UnknownKeyException_create_Object_Throwable.getCallTargetForceInit())", inline = false) DirectCallNode createWithKeyAndCause) {
EspressoContext context = EspressoContext.get(node);
Meta meta = context.getMeta();
StaticObject unknownKey = InteropUtils.maybeWrapAsObject(e.getUnknownKey(), keyInterop, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.oracle.truffle.espresso.impl.ObjectKlass;
import com.oracle.truffle.espresso.meta.EspressoError;
import com.oracle.truffle.espresso.meta.Meta;
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
import com.oracle.truffle.espresso.nodes.bytecodes.InvokeInterface;
import com.oracle.truffle.espresso.runtime.EspressoContext;
import com.oracle.truffle.espresso.runtime.JavaVersion;
Expand Down Expand Up @@ -332,7 +333,7 @@ static int doDefault(StaticObject self,

@GenerateInline
@GenerateUncached
abstract static class JavaRegexCompileNode extends Node {
abstract static class JavaRegexCompileNode extends EspressoInlineNode {
public abstract Object execute(Node node, StaticObject self, RegexAction action, Field destination, EspressoContext context);

@Specialization
Expand Down Expand Up @@ -458,7 +459,7 @@ private static int getGroupCount(Object regexObject, InteropLibrary regexObjectI

@GenerateInline
@GenerateUncached
public abstract static class JavaRegexExecNode extends Node {
public abstract static class JavaRegexExecNode extends EspressoInlineNode {
public abstract boolean execute(Node node, Object regexObject, StaticObject self, int from, Meta meta);

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
import com.oracle.truffle.espresso.meta.JavaKind;
import com.oracle.truffle.espresso.meta.Meta;
import com.oracle.truffle.espresso.meta.MetaUtil;
import com.oracle.truffle.espresso.nodes.EspressoNode;
import com.oracle.truffle.espresso.nodes.EspressoInlineNode;
import com.oracle.truffle.espresso.runtime.EspressoContext;
import com.oracle.truffle.espresso.runtime.EspressoException;
import com.oracle.truffle.espresso.runtime.GuestAllocator;
Expand Down Expand Up @@ -905,23 +905,26 @@ public static long objectFieldOffset1(@JavaType(Unsafe.class) StaticObject self,

@GenerateInline
@GenerateCached(false)
abstract static class GetFieldFromIndexNode extends EspressoNode {
abstract static class GetFieldFromIndexNode extends EspressoInlineNode {
static final int LIMIT = 3;

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

@Specialization(guards = {"slot == cachedSlot", "holder.isStaticStorage() == cachedIsStaticStorage", "holder.getKlass() == cachedKlass"}, limit = "LIMIT")
static Field doCached(@SuppressWarnings("unused") StaticObject holder, @SuppressWarnings("unused") long slot,
@SuppressWarnings("unused") @Bind("$node") Node node,
@SuppressWarnings("unused") @Cached("slot") long cachedSlot,
@SuppressWarnings("unused") @Cached("holder.getKlass()") Klass cachedKlass,
@SuppressWarnings("unused") @Cached("holder.isStaticStorage()") boolean cachedIsStaticStorage,
@Cached("doGeneric(holder, slot)") Field cachedField) {
@Cached("doGeneric(holder, slot, node)") Field cachedField) {
return cachedField;
}

@Specialization(replaces = "doCached")
Field doGeneric(StaticObject holder, long slot) {
return resolveUnsafeAccessField(holder, slot, getMeta(), getLanguage());
static Field doGeneric(StaticObject holder, long slot,
@Bind("$node") Node node) {
Meta meta = EspressoContext.get(node).getMeta();
return resolveUnsafeAccessField(holder, slot, meta, EspressoLanguage.get(node));
}
}

Expand Down