# HG changeset patch # User Doug Simon # Date 1364295702 -3600 # Node ID f71fec3fadae94951488a555707faca9b202c0fe # Parent 809819548c05bb4d883ee922013a4badf6a78e8c made method substitutions for Thread be interpretable diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRuntime.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRuntime.java Tue Mar 26 12:01:42 2013 +0100 @@ -142,7 +142,7 @@ addRuntimeCall(THREAD_IS_INTERRUPTED, config.threadIsInterruptedStub, /* temps */ null, - /* ret */ rax.asValue(Kind.Int), + /* ret */ rax.asValue(Kind.Boolean), /* arg0: thread */ javaCallingConvention(Kind.Object, /* arg1: clearInterrupted */ Kind.Boolean)); diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Tue Mar 26 12:01:42 2013 +0100 @@ -104,6 +104,16 @@ return unsafe.getInt(address); } + /** + * Reads a word value from a given object. + */ + public static long unsafeReadWord(Object object, long offset) { + if (wordKind == Kind.Long) { + return unsafe.getLong(object, offset); + } + return unsafe.getInt(object, offset); + } + protected/* final */CompilerToVM compilerToVm; protected/* final */VMToCompiler vmToCompiler; diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentThread.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentThread.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentThread.java Tue Mar 26 12:01:42 2013 +0100 @@ -46,5 +46,7 @@ } @NodeIntrinsic - public static native Thread get(); + public static Thread get() { + return Thread.currentThread(); + } } diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ThreadIsInterruptedStubCall.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ThreadIsInterruptedStubCall.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ThreadIsInterruptedStubCall.java Tue Mar 26 12:01:42 2013 +0100 @@ -22,11 +22,14 @@ */ package com.oracle.graal.hotspot.nodes; +import java.lang.reflect.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; import com.oracle.graal.api.meta.*; import com.oracle.graal.compiler.gen.*; import com.oracle.graal.compiler.target.*; +import com.oracle.graal.graph.*; import com.oracle.graal.lir.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.type.*; @@ -38,7 +41,7 @@ @Input private final ValueNode thread; @Input private final ValueNode clearIsInterrupted; - public static final Descriptor THREAD_IS_INTERRUPTED = new Descriptor("thread_is_interrupted", false, int.class, Object.class, boolean.class); + public static final Descriptor THREAD_IS_INTERRUPTED = new Descriptor("thread_is_interrupted", false, boolean.class, Object.class, boolean.class); public ThreadIsInterruptedStubCall(ValueNode thread, ValueNode clearIsInterrupted) { super(StampFactory.forInteger(Kind.Int, 0, 1)); @@ -54,5 +57,13 @@ } @NodeIntrinsic - public static native int call(Thread thread, boolean clearIsInterrupted); + public static boolean call(Thread thread, boolean clearIsInterrupted) { + try { + Method isInterrupted = Thread.class.getDeclaredMethod("isInterrupted", boolean.class); + isInterrupted.setAccessible(true); + return (Boolean) isInterrupted.invoke(thread, clearIsInterrupted); + } catch (Exception e) { + throw new GraalInternalError(e); + } + } } diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSnippetUtils.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSnippetUtils.java Tue Mar 26 12:01:42 2013 +0100 @@ -22,6 +22,7 @@ */ package com.oracle.graal.hotspot.replacements; +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*; import sun.misc.*; @@ -33,7 +34,7 @@ import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.hotspot.nodes.*; import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.replacements.Snippet.*; +import com.oracle.graal.replacements.Snippet.Fold; import com.oracle.graal.replacements.nodes.*; import com.oracle.graal.word.*; @@ -356,8 +357,11 @@ @NodeIntrinsic(value = ReadRegisterNode.class, setStampFromReturnType = true) public static native Word registerAsWord(@ConstantNodeParameter Register register, @ConstantNodeParameter boolean directUse, @ConstantNodeParameter boolean incoming); + @SuppressWarnings("unused") @NodeIntrinsic(value = UnsafeLoadNode.class, setStampFromReturnType = true) - private static native Word loadWordFromObjectIntrinsic(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind wordKind); + private static Word loadWordFromObjectIntrinsic(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind wordKind) { + return Word.box(unsafeReadWord(object, offset + displacement)); + } @NodeIntrinsic(value = LoadHubNode.class, setStampFromReturnType = true) static native Word loadHubIntrinsic(Object object, @ConstantNodeParameter Kind word); diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ThreadSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ThreadSubstitutions.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ThreadSubstitutions.java Tue Mar 26 12:01:42 2013 +0100 @@ -59,13 +59,12 @@ if (thisObject == thread) { Word rawThread = loadWordFromObject(thread, eetopOffset()); Word osThread = rawThread.readWord(osThreadOffset(), FINAL_LOCATION); - int int0 = osThread.readInt(osThreadInterruptedOffset(), UNKNOWN_LOCATION); - boolean interrupted = int0 != 0; + boolean interrupted = osThread.readInt(osThreadInterruptedOffset(), UNKNOWN_LOCATION) != 0; if (!interrupted || !clearInterrupted) { return interrupted; } } - return ThreadIsInterruptedStubCall.call(thisObject, clearInterrupted) != 0; + return ThreadIsInterruptedStubCall.call(thisObject, clearInterrupted); } } diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java Tue Mar 26 12:01:42 2013 +0100 @@ -109,6 +109,9 @@ @NodeIntrinsic public static native T unsafeCast(Object object, @ConstantNodeParameter Stamp stamp); + @SuppressWarnings("unused") @NodeIntrinsic - public static native T unsafeCast(Object object, @ConstantNodeParameter Class toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull); + public static T unsafeCast(Object object, @ConstantNodeParameter Class toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull) { + return toType.cast(object); + } } diff -r 809819548c05 -r f71fec3fadae graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Tue Mar 26 11:46:35 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Tue Mar 26 12:01:42 2013 +0100 @@ -68,8 +68,8 @@ } // @formatter:on - private static Word box(long val) { - return HostedWord.box(val); + public static Word box(long val) { + return HostedWord.boxLong(val); } protected abstract long unbox(); @@ -1054,7 +1054,7 @@ this.rawValue = rawValue; } - protected static Word box(long val) { + protected static Word boxLong(long val) { if (val >= SMALL_FROM && val <= SMALL_TO) { return smallCache[(int) val - SMALL_FROM]; }