# HG changeset patch # User Christian Haeubl # Date 1364471930 -3600 # Node ID cd9e8dd9f4882e808449db53bc263edfd396be8d # Parent 02ef91b94656e3af98a1dc0bc475a96a90ce09eb# Parent da674936800c9ed467a2f2b298d0a63f184c6fa2 Merge. diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/Alias.java --- a/graal/com.oracle.graal.api.replacements/src/com/oracle/graal/api/replacements/Alias.java Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2013, 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.graal.api.replacements; - -import java.lang.annotation.*; - -/** - * Mechanism for accessing fields and methods otherwise inaccessible due to Java language access - * control rules. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.FIELD}) -public @interface Alias { - - /** - * The name of the aliased field or method. If the default value is specified for this element, - * then the name of the annotated field or method is implied. - */ - String name() default ""; - - /** - * Gets the field - * descriptor of the aliased field or the method - * descriptor of the aliased method. - *

- * If the default value is specified for this element, then the descriptor of the annotated - * field or method is implied. - */ - String descriptor() default ""; - - /** - * Specifies the class in which the aliased field or method is declared. If the default value is - * specified for this element, then a non-default value must be given for the - * {@link #declaringClassName()} element. - */ - Class declaringClass() default Alias.class; - - /** - * Specifies the class in which the aliased field or method is declared. This method is provided - * for cases where the declaring class is not accessible (according to Java language access - * control rules) in the scope of the alias method. - * - * If the default value is specified for this element, then a non-default value must be given - * for the {@link #declaringClassName()} element. - */ - String declaringClassName() default ""; - - /** - * Specifies the suffix of the declaring class name if it is an inner class. - */ - String innerClass() default ""; - - /** - * Specifies if the aliased target must exist. This property is useful, for example, to handle - * differences in JDK versions for private methods. - */ - boolean optional() default false; -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/ServiceProvider.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.api.runtime/src/com/oracle/graal/api/runtime/ServiceProvider.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2013, 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.graal.api.runtime; + +import java.lang.annotation.*; + +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.TYPE) +public @interface ServiceProvider { + + Class value(); +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/DegeneratedLoopsTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/DegeneratedLoopsTest.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/DegeneratedLoopsTest.java Thu Mar 28 12:58:50 2013 +0100 @@ -27,6 +27,7 @@ import com.oracle.graal.api.code.*; import com.oracle.graal.debug.*; import com.oracle.graal.nodes.*; +import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; /** @@ -80,13 +81,11 @@ public void run() { StructuredGraph graph = parse(snippet); + new InliningPhase(runtime(), null, new Assumptions(false), null, getDefaultPhasePlan(), OptimisticOptimizations.ALL).apply(graph); + new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); Debug.dump(graph, "Graph"); - for (Invoke invoke : graph.getInvokes()) { - invoke.intrinsify(null); - } - new CanonicalizerPhase(runtime(), new Assumptions(false)).apply(graph); StructuredGraph referenceGraph = parse(REFERENCE_SNIPPET); - Debug.dump(referenceGraph, "Graph"); + Debug.dump(referenceGraph, "ReferenceGraph"); assertEquals(referenceGraph, graph); } }); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraphScheduleTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraphScheduleTest.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/GraphScheduleTest.java Thu Mar 28 12:58:50 2013 +0100 @@ -47,11 +47,11 @@ Block block = bBlock; while (block != null) { if (block == aBlock) { - break; + return; } block = block.getDominator(); } - Assert.assertSame(block, aBlock); + Assert.fail("block of A doesn't dominate the block of B"); } } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCast.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCast.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2013, 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.graal.compiler.test; + +import java.util.*; + +import org.junit.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.debug.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.phases.common.*; + +/* consider + * B b = (B) a; + * return b.x10; + * + * With snippets a typecheck is performed and if it was successful, a UnsafeCastNode is created. + * For the read node, however, there is only a dependency to the UnsafeCastNode, but not to the + * typecheck itself. With special crafting, it's possible to get the scheduler moving the + * FloatingReadNode before the typecheck. Assuming the object is of the wrong type (here for + * example A), an invalid field read is done. + * + * In order to avoid this situation, an anchor node is introduced in CheckCastSnippts. + */ + +public class ReadAfterCheckCast extends GraphScheduleTest { + + public static long foo = 0; + + public static class A { + + public long x1; + } + + public static class B extends A { + + public long x10; + } + + public static long test1Snippet(A a) { + if (foo > 4) { + B b = (B) a; + b.x10 += 1; + return b.x10; + } else { + B b = (B) a; + b.x10 += 1; + return b.x10; + } + } + + @Test + public void test1() { + test("test1Snippet"); + } + + private void test(final String snippet) { + Debug.scope("FloatingReadTest", new DebugDumpScope(snippet), new Runnable() { + + // check shape of graph, with lots of assumptions. will probably fail if graph + // structure changes significantly + public void run() { + StructuredGraph graph = parse(snippet); + new LoweringPhase(null, runtime(), new Assumptions(false)).apply(graph); + new FloatingReadPhase().apply(graph); + new EliminatePartiallyRedundantGuardsPhase(true, false).apply(graph); + new ReadEliminationPhase().apply(graph); + new CanonicalizerPhase(runtime(), null).apply(graph); + + Debug.dump(graph, "After lowering"); + + ArrayList merges = new ArrayList<>(); + ArrayList reads = new ArrayList<>(); + for (Node n : graph.getNodes()) { + if (n instanceof MergeNode) { + // check shape + MergeNode merge = (MergeNode) n; + + if (merge.inputs().count() == 2) { + for (EndNode m : merge.forwardEnds()) { + if (m.predecessor() != null && m.predecessor() instanceof BeginNode && m.predecessor().predecessor() instanceof IfNode) { + IfNode o = (IfNode) m.predecessor().predecessor(); + if (o.falseSuccessor().next() instanceof DeoptimizeNode) { + merges.add(merge); + } + } + } + } + } + if (n instanceof IntegerAddNode) { + IntegerAddNode ian = (IntegerAddNode) n; + + Assert.assertTrue(ian.y() instanceof ConstantNode); + Assert.assertTrue(ian.x() instanceof FloatingReadNode); + reads.add((FloatingReadNode) ian.x()); + } + } + + Assert.assertTrue(merges.size() >= reads.size()); + for (int i = 0; i < reads.size(); i++) { + assertOrderedAfterSchedule(graph, merges.get(i), reads.get(i)); + } + } + }); + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/GraalCompiler.java Thu Mar 28 12:58:50 2013 +0100 @@ -200,6 +200,10 @@ new EliminatePartiallyRedundantGuardsPhase(true, true).apply(graph); } + if (GraalOptions.OptCanonicalizer) { + new CanonicalizerPhase(runtime, assumptions).apply(graph); + } + plan.runPhases(PhasePosition.MID_LEVEL, graph); plan.runPhases(PhasePosition.LOW_LEVEL, graph); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java --- a/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.graph/src/com/oracle/graal/graph/Node.java Thu Mar 28 12:58:50 2013 +0100 @@ -86,9 +86,6 @@ * annotated method can be replaced with an instance of the node class denoted by * {@link #value()}. For this reason, the signature of the annotated method must match the * signature of a constructor in the node class. - *

- * All methods annotated with this annotation must be declared native to ensure they throw a - * {@link UnsatisfiedLinkError} if called by non-Graal compiled code. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.amd64/src/com/oracle/graal/hotspot/amd64/AMD64HotSpotRuntime.java Thu Mar 28 12:58:50 2013 +0100 @@ -41,6 +41,8 @@ import static com.oracle.graal.hotspot.replacements.AESCryptSubstitutions.EncryptBlockStubCall.*; import static com.oracle.graal.hotspot.replacements.CipherBlockChainingSubstitutions.DecryptAESCryptStubCall.*; import static com.oracle.graal.hotspot.replacements.CipherBlockChainingSubstitutions.EncryptAESCryptStubCall.*; +import static com.oracle.graal.hotspot.nodes.WriteBarrierPostStubCall.*; +import static com.oracle.graal.hotspot.nodes.WriteBarrierPreStubCall.*; import com.oracle.graal.api.code.*; import com.oracle.graal.api.meta.*; @@ -50,8 +52,8 @@ import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.nodes.calc.*; import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.replacements.amd64.*; import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.amd64.*; public class AMD64HotSpotRuntime extends HotSpotRuntime { @@ -88,6 +90,16 @@ /* arg0: object */ javaCallingConvention(Kind.Object, /* arg1: lock */ word)); + addRuntimeCall(WBPRECALL, config.wbPreCallStub, + /* temps */ null, + /* ret */ ret(Kind.Void), + /* arg0: object */ javaCallingConvention(Kind.Object)); + + addRuntimeCall(WBPOSTCALL, config.wbPostCallStub, + /* temps */ null, + /* ret */ ret(Kind.Void), + /* arg0: object */ javaCallingConvention(Kind.Object, word)); + addRuntimeCall(MONITOREXIT, config.monitorExitStub, /* temps */ null, /* ret */ ret(Kind.Void), @@ -142,7 +154,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 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/HotSpotMethodSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/HotSpotMethodSubstitutionTest.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/HotSpotMethodSubstitutionTest.java Thu Mar 28 12:58:50 2013 +0100 @@ -25,6 +25,7 @@ import org.junit.*; import com.oracle.graal.api.replacements.*; +import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.replacements.*; /** @@ -36,6 +37,11 @@ public void testObjectSubstitutions() { test("getClass_"); test("objectHashCode"); + + Object obj = new Object(); + + assertEquals("a string".getClass(), ObjectSubstitutions.getClass("a string")); + assertEquals(obj.hashCode(), ObjectSubstitutions.hashCode(obj)); } @SuppressWarnings("all") @@ -57,6 +63,18 @@ test("isPrimitive"); test("getSuperClass"); test("getComponentType"); + + for (Class c : new Class[]{getClass(), Cloneable.class, int[].class, String[][].class}) { + assertEquals(c.getModifiers(), ClassSubstitutions.getModifiers(c)); + assertEquals(c.isInterface(), ClassSubstitutions.isInterface(c)); + assertEquals(c.isArray(), ClassSubstitutions.isArray(c)); + assertEquals(c.isPrimitive(), ClassSubstitutions.isPrimitive(c)); + assertEquals(c.getSuperclass(), ClassSubstitutions.getSuperclass(c)); + assertEquals(c.getComponentType(), ClassSubstitutions.getComponentType(c)); + for (Object o : new Object[]{this, new int[5], new String[2][], new Object()}) { + assertEquals(c.isInstance(o), ClassSubstitutions.isInstance(c, o)); + } + } } @SuppressWarnings("all") @@ -99,6 +117,10 @@ test("currentThread"); test("threadIsInterrupted"); test("threadInterrupted"); + + Thread currentThread = Thread.currentThread(); + assertEquals(currentThread, ThreadSubstitutions.currentThread()); + assertEquals(currentThread.isInterrupted(), ThreadSubstitutions.isInterrupted(currentThread, false)); } @SuppressWarnings("all") @@ -120,6 +142,12 @@ public void testSystemSubstitutions() { test("systemTime"); test("systemIdentityHashCode"); + + SystemSubstitutions.currentTimeMillis(); + SystemSubstitutions.nanoTime(); + for (Object o : new Object[]{this, new int[5], new String[2][], new Object()}) { + assertEquals(System.identityHashCode(o), SystemSubstitutions.identityHashCode(o)); + } } @SuppressWarnings("all") diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/CompilationTask.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,7 +22,6 @@ */ package com.oracle.graal.hotspot; -import static com.oracle.graal.nodes.StructuredGraph.*; import static com.oracle.graal.phases.common.InliningUtil.*; import java.util.concurrent.*; @@ -36,6 +35,7 @@ import com.oracle.graal.hotspot.meta.*; import com.oracle.graal.nodes.*; import com.oracle.graal.phases.*; +import static com.oracle.graal.nodes.StructuredGraph.*; public final class CompilationTask implements Runnable, Comparable { @@ -88,6 +88,10 @@ return inProgress; } + public boolean isCancelled() { + return cancelled; + } + public int getEntryBCI() { return entryBCI; } @@ -106,10 +110,11 @@ } } runCompilation(); - if (method.currentTask() == this && entryBCI == StructuredGraph.INVOCATION_ENTRY_BCI) { + } finally { + if (method.currentTask() == this) { method.setCurrentTask(null); } - } finally { + graalRuntime.getCompilerToVM().clearQueuedForCompilation(method); inProgress = false; withinEnqueue.set(Boolean.TRUE); } diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Thu Mar 28 12:58:50 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 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java Thu Mar 28 12:58:50 2013 +0100 @@ -42,6 +42,7 @@ public boolean useBiasedLocking; public boolean usePopCountInstruction; public boolean useAESIntrinsics; + public boolean useG1GC; // offsets, ... public int stackShadowPages; @@ -216,6 +217,16 @@ public boolean isPollingPageFar; /** + * G1 Collector Related Values. + */ + public int g1CardQueueIndexOffset; + public int g1CardQueueBufferOffset; + public int logOfHRGrainBytes; + public int g1SATBQueueMarkingOffset; + public int g1SATBQueueIndexOffset; + public int g1SATBQueueBufferOffset; + + /** * The offset of the _java_mirror field (of type {@link Class}) in a Klass. */ public int classMirrorOffset; @@ -317,6 +328,9 @@ public long handleDeoptStub; public long monitorEnterStub; public long monitorExitStub; + public long wbPreCallStub; + public long wbPostCallStub; + public long verifyOopStub; public long vmErrorStub; public long deoptimizeStub; diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Thu Mar 28 12:58:50 2013 +0100 @@ -213,6 +213,8 @@ String getFileName(HotSpotResolvedJavaType method); + void clearQueuedForCompilation(HotSpotResolvedJavaMethod method); + /** * Invalidates the profiling information and restarts profiling upon the next invocation. * diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Thu Mar 28 12:58:50 2013 +0100 @@ -154,5 +154,8 @@ public native String getFileName(HotSpotResolvedJavaType method); @Override + public native void clearQueuedForCompilation(HotSpotResolvedJavaMethod method); + + @Override public native void reprofile(long metaspaceMethod); } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/VMToCompilerImpl.java Thu Mar 28 12:58:50 2013 +0100 @@ -439,7 +439,7 @@ if (osrCompilation && bootstrapRunning) { // no OSR compilations during bootstrap - the compiler is just too slow at this point, // and we know that there are no endless loops - return current != null; + return current != null && (current.isInProgress() || !current.isCancelled()); } if (CompilationTask.withinEnqueue.get()) { @@ -447,7 +447,7 @@ // java.util.concurrent.BlockingQueue is used to implement the compilation worker // queues. If a compiler thread triggers a compilation, then it may be blocked trying // to add something to its own queue. - return current != null; + return current != null && (current.isInProgress() || !current.isCancelled()); } CompilationTask.withinEnqueue.set(Boolean.TRUE); @@ -464,7 +464,7 @@ // normally compilation tasks will only be re-queued when they get a // priority boost, so cancel the old task and add a new one current.cancel(); - } else { + } else if (!current.isCancelled()) { // without a prioritizing compile queue it makes no sense to re-queue the // compilation task return true; diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Thu Mar 28 12:58:50 2013 +0100 @@ -35,7 +35,7 @@ import static com.oracle.graal.nodes.java.RegisterFinalizerNode.*; import static com.oracle.graal.replacements.Log.*; import static com.oracle.graal.replacements.MathSubstitutionsX86.*; - +import com.oracle.graal.replacements.*; import java.lang.reflect.*; import java.util.*; @@ -69,7 +69,6 @@ import com.oracle.graal.nodes.type.*; import com.oracle.graal.phases.*; import com.oracle.graal.printer.*; -import com.oracle.graal.replacements.*; import com.oracle.graal.word.*; /** @@ -87,6 +86,7 @@ private InstanceOfSnippets.Templates instanceofSnippets; private NewObjectSnippets.Templates newObjectSnippets; private MonitorSnippets.Templates monitorSnippets; + private WriteBarrierSnippets.Templates writeBarrierSnippets; private NewInstanceStub newInstanceStub; private NewArrayStub newArrayStub; @@ -265,7 +265,6 @@ /* ret */ ret(Kind.Void), /* arg0: object */ javaCallingConvention(Kind.Object, /* arg1: flags */ Kind.Int)); - // @formatter:on } @@ -353,11 +352,13 @@ installer.installSnippets(NewInstanceStub.class); installer.installSnippets(NewArrayStub.class); + installer.installSnippets(WriteBarrierSnippets.class); checkcastSnippets = new CheckCastSnippets.Templates(this, assumptions, graalRuntime.getTarget()); instanceofSnippets = new InstanceOfSnippets.Templates(this, assumptions, graalRuntime.getTarget()); newObjectSnippets = new NewObjectSnippets.Templates(this, assumptions, graalRuntime.getTarget(), config.useTLAB); monitorSnippets = new MonitorSnippets.Templates(this, assumptions, graalRuntime.getTarget(), config.useFastLocking); + writeBarrierSnippets = new WriteBarrierSnippets.Templates(this, assumptions, graalRuntime.getTarget()); newInstanceStub = new NewInstanceStub(this, assumptions, graalRuntime.getTarget()); newArrayStub = new NewArrayStub(this, assumptions, graalRuntime.getTarget()); @@ -580,10 +581,17 @@ LoadFieldNode loadField = (LoadFieldNode) n; HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) loadField.field(); ValueNode object = loadField.isStatic() ? ConstantNode.forObject(field.getDeclaringClass().mirror(), this, graph) : loadField.object(); + LocationNode location = LocationNode.create(field, field.getKind(), field.offset(), graph); assert loadField.kind() != Kind.Illegal; ReadNode memoryRead = graph.add(new ReadNode(object, LocationNode.create(field, field.getKind(), field.offset(), graph), loadField.stamp())); memoryRead.dependencies().add(tool.createNullCheckGuard(object)); + graph.replaceFixedWithFixed(loadField, memoryRead); + if (config.useG1GC && field.getKind() == Kind.Object && field.getDeclaringClass().getName().toString().equals("Ljava/lang/ref/Reference;") && field.getName().equals("referent")) { + WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(memoryRead.object(), memoryRead, location, false)); + graph.addAfterFixed(memoryRead, writeBarrierPre); + } + if (loadField.isVolatile()) { MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_READ)); graph.addBeforeFixed(memoryRead, preMembar); @@ -594,19 +602,25 @@ StoreFieldNode storeField = (StoreFieldNode) n; HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) storeField.field(); ValueNode object = storeField.isStatic() ? ConstantNode.forObject(field.getDeclaringClass().mirror(), this, graph) : storeField.object(); - WriteNode memoryWrite = graph.add(new WriteNode(object, storeField.value(), LocationNode.create(field, field.getKind(), field.offset(), graph))); + LocationNode location = LocationNode.create(field, field.getKind(), field.offset(), graph); + WriteNode memoryWrite = graph.add(new WriteNode(object, storeField.value(), location)); memoryWrite.dependencies().add(tool.createNullCheckGuard(object)); memoryWrite.setStateAfter(storeField.stateAfter()); graph.replaceFixedWithFixed(storeField, memoryWrite); FixedWithNextNode last = memoryWrite; + FixedWithNextNode first = memoryWrite; + if (field.getKind() == Kind.Object && !memoryWrite.value().objectStamp().alwaysNull()) { - FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(memoryWrite.object())); - graph.addAfterFixed(memoryWrite, writeBarrier); - last = writeBarrier; + WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(memoryWrite.object(), null, memoryWrite.location(), true)); + WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(memoryWrite.object(), memoryWrite.value(), memoryWrite.location(), false)); + graph.addBeforeFixed(memoryWrite, writeBarrierPre); + graph.addAfterFixed(memoryWrite, writeBarrierPost); + first = writeBarrierPre; + last = writeBarrierPost; } if (storeField.isVolatile()) { MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_WRITE)); - graph.addBeforeFixed(memoryWrite, preMembar); + graph.addBeforeFixed(first, preMembar); MembarNode postMembar = graph.add(new MembarNode(JMM_POST_VOLATILE_WRITE)); graph.addAfterFixed(last, postMembar); } @@ -614,16 +628,17 @@ // Separate out GC barrier semantics CompareAndSwapNode cas = (CompareAndSwapNode) n; ValueNode expected = cas.expected(); + LocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, cas.expected().kind(), cas.displacement(), cas.offset(), graph, 1); if (expected.kind() == Kind.Object && !cas.newValue().objectStamp().alwaysNull()) { ResolvedJavaType type = cas.object().objectStamp().type(); + WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(cas.object(), null, location, true)); + graph.addBeforeFixed(cas, writeBarrierPre); if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) { - // Use a field write barrier since it's not an array store - FieldWriteBarrier writeBarrier = graph.add(new FieldWriteBarrier(cas.object())); - graph.addAfterFixed(cas, writeBarrier); + WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, false)); + graph.addAfterFixed(cas, writeBarrierPost); } else { - // This may be an array store so use an array write barrier - LocationNode location = IndexedLocationNode.create(LocationNode.ANY_LOCATION, cas.expected().kind(), cas.displacement(), cas.offset(), graph, 1); - graph.addAfterFixed(cas, graph.add(new ArrayWriteBarrier(cas.object(), location))); + WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(cas.object(), cas.newValue(), location, true)); + graph.addAfterFixed(cas, writeBarrierPost); } } } else if (n instanceof LoadIndexedNode) { @@ -637,7 +652,6 @@ } else if (n instanceof StoreIndexedNode) { StoreIndexedNode storeIndexed = (StoreIndexedNode) n; ValueNode boundsCheck = createBoundsCheck(storeIndexed, tool); - Kind elementKind = storeIndexed.elementKind(); LocationNode arrayLocation = createArrayLocation(graph, elementKind, storeIndexed.index()); ValueNode value = storeIndexed.value(); @@ -665,11 +679,13 @@ WriteNode memoryWrite = graph.add(new WriteNode(array, value, arrayLocation)); memoryWrite.dependencies().add(boundsCheck); memoryWrite.setStateAfter(storeIndexed.stateAfter()); - graph.replaceFixedWithFixed(storeIndexed, memoryWrite); if (elementKind == Kind.Object && !value.objectStamp().alwaysNull()) { - graph.addAfterFixed(memoryWrite, graph.add(new ArrayWriteBarrier(array, arrayLocation))); + WriteBarrierPre writeBarrierPre = graph.add(new WriteBarrierPre(array, null, arrayLocation, true)); + graph.addBeforeFixed(memoryWrite, writeBarrierPre); + WriteBarrierPost writeBarrierPost = graph.add(new WriteBarrierPost(array, value, arrayLocation, true)); + graph.addAfterFixed(memoryWrite, writeBarrierPost); } } else if (n instanceof UnsafeLoadNode) { UnsafeLoadNode load = (UnsafeLoadNode) n; @@ -689,15 +705,13 @@ graph.replaceFixedWithFixed(store, write); if (write.value().kind() == Kind.Object && !write.value().objectStamp().alwaysNull()) { ResolvedJavaType type = object.objectStamp().type(); - WriteBarrier writeBarrier; + WriteBarrierPre writeBarrierPre = new WriteBarrierPre(object, null, location, true); + graph.addBeforeFixed(write, graph.add(writeBarrierPre)); if (type != null && !type.isArray() && !MetaUtil.isJavaLangObject(type)) { - // Use a field write barrier since it's not an array store - writeBarrier = graph.add(new FieldWriteBarrier(object)); + graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, false))); } else { - // This may be an array store so use an array write barrier - writeBarrier = graph.add(new ArrayWriteBarrier(object, location)); + graph.addAfterFixed(write, graph.add(new WriteBarrierPost(object, write.value(), location, true))); } - graph.addAfterFixed(write, writeBarrier); } } else if (n instanceof LoadHubNode) { LoadHubNode loadHub = (LoadHubNode) n; @@ -729,6 +743,12 @@ monitorSnippets.lower((MonitorEnterNode) n, tool); } else if (n instanceof MonitorExitNode) { monitorSnippets.lower((MonitorExitNode) n, tool); + } else if (n instanceof SerialWriteBarrierPost) { + writeBarrierSnippets.lower((SerialWriteBarrierPost) n, tool); + } else if (n instanceof G1WriteBarrierPre) { + writeBarrierSnippets.lower((G1WriteBarrierPre) n, tool); + } else if (n instanceof G1WriteBarrierPost) { + writeBarrierSnippets.lower((G1WriteBarrierPost) n, tool); } else if (n instanceof TLABAllocateNode) { newObjectSnippets.lower((TLABAllocateNode) n, tool); } else if (n instanceof InitializeObjectNode) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ArrayWriteBarrier.java Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2012, 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.graal.hotspot.nodes; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.extended.*; -import com.oracle.graal.nodes.spi.*; - -public final class ArrayWriteBarrier extends WriteBarrier implements LIRLowerable { - - @Input private ValueNode object; - @Input private LocationNode location; - - public ValueNode object() { - return object; - } - - public LocationNode location() { - return location; - } - - public ArrayWriteBarrier(ValueNode object, LocationNode location) { - this.object = object; - this.location = location; - } - - @Override - public void generate(LIRGeneratorTool gen) { - Value addr = location().generateLea(gen, object()); - generateBarrier(addr, gen); - } -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentJavaThreadNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/CurrentJavaThreadNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.hotspot.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; +import com.oracle.graal.word.*; + +/** + * Gets the address of the C++ JavaThread object for the current thread. + */ +public class CurrentJavaThreadNode extends FloatingNode implements LIRLowerable { + + public CurrentJavaThreadNode() { + super(StampFactory.forWord()); + } + + @Override + public void generate(LIRGeneratorTool gen) { + Register rawThread = HotSpotGraalRuntime.getInstance().getRuntime().threadRegister(); + gen.setResult(this, rawThread.asValue(this.kind())); + } + + private static int eetopOffset() { + try { + return (int) UnsafeAccess.unsafe.objectFieldOffset(Thread.class.getDeclaredField("eetop")); + } catch (Exception e) { + throw new GraalInternalError(e); + } + } + + @NodeIntrinsic + public static Word get() { + return Word.box(unsafeReadWord(Thread.currentThread(), eetopOffset())); + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2011, 2012, 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.graal.hotspot.nodes; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; - -/** - * A node that loads the {@link Thread} object for the current thread. - */ -public final class CurrentThread extends FloatingNode implements LIRLowerable { - - public CurrentThread() { - super(StampFactory.declaredNonNull(HotSpotGraalRuntime.getInstance().getRuntime().lookupJavaType(Thread.class))); - } - - @Override - public void generate(LIRGeneratorTool gen) { - HotSpotGraalRuntime runtime = HotSpotGraalRuntime.getInstance(); - Register thread = runtime.getRuntime().threadRegister(); - gen.setResult(this, gen.emitLoad(Kind.Object, thread.asValue(gen.target().wordKind), runtime.getConfig().threadObjectOffset, Value.ILLEGAL, 0, false)); - } - - @NodeIntrinsic - public static native Thread get(); -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/FieldWriteBarrier.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/FieldWriteBarrier.java Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2012, 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.graal.hotspot.nodes; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; - -public final class FieldWriteBarrier extends WriteBarrier implements LIRLowerable { - - @Input private ValueNode object; - - public ValueNode object() { - return object; - } - - public FieldWriteBarrier(ValueNode object) { - this.object = object; - } - - @Override - public void generate(LIRGeneratorTool generator) { - Value obj = generator.newVariable(generator.target().wordKind); - generator.emitMove(obj, generator.operand(object())); - generateBarrier(obj, generator); - } -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/FixedValueAnchorNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/FixedValueAnchorNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; + +public final class FixedValueAnchorNode extends FixedWithNextNode implements LIRLowerable { + + @Input private ValueNode object; + + public ValueNode object() { + return object; + } + + public FixedValueAnchorNode(ValueNode object) { + super(StampFactory.forNodeIntrinsic()); + this.object = object; + + } + + @Override + public boolean inferStamp() { + return updateStamp(object.stamp()); + } + + @NodeIntrinsic + public static native T getObject(Object object); + + @Override + public void generate(LIRGeneratorTool generator) { + generator.setResult(this, generator.operand(object)); + } + +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPost.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPost.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; + +public class G1WriteBarrierPost extends WriteBarrierPost implements Lowerable { + + @Input private ValueNode object; + @Input private ValueNode value; + @Input private LocationNode location; + private final boolean precise; + + @Override + public ValueNode getObject() { + return object; + } + + @Override + public ValueNode getValue() { + return value; + } + + @Override + public LocationNode getLocation() { + return location; + } + + @Override + public boolean usePrecise() { + return precise; + } + + public G1WriteBarrierPost(ValueNode object, ValueNode value, LocationNode location, boolean precise) { + this.object = object; + this.value = value; + this.location = location; + this.precise = precise; + } + + @Override + public void lower(LoweringTool generator) { + generator.getRuntime().lower(this, generator); + } + +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPre.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/G1WriteBarrierPre.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; + +public final class G1WriteBarrierPre extends WriteBarrierPre implements Lowerable { + + @Input private ValueNode object; + @Input private LocationNode location; + @Input private ValueNode expectedObject; + private final boolean doLoad; + + @Override + public ValueNode getObject() { + return object; + } + + @Override + public ValueNode getExpectedObject() { + return expectedObject; + } + + @Override + public boolean doLoad() { + return doLoad; + } + + @Override + public LocationNode getLocation() { + return location; + } + + public G1WriteBarrierPre(ValueNode object, ValueNode expectedObject, LocationNode location, boolean doLoad) { + this.object = object; + this.doLoad = doLoad; + this.location = location; + this.expectedObject = expectedObject; + } + + @Override + public void lower(LoweringTool generator) { + generator.getRuntime().lower(this, generator); + } + +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/HotSpotCurrentRawThreadNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/HotSpotCurrentRawThreadNode.java Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2012, 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.graal.hotspot.nodes; - -import com.oracle.graal.api.code.*; -import com.oracle.graal.hotspot.*; -import com.oracle.graal.nodes.calc.*; -import com.oracle.graal.nodes.spi.*; -import com.oracle.graal.nodes.type.*; -import com.oracle.graal.word.*; - -public class HotSpotCurrentRawThreadNode extends FloatingNode implements LIRLowerable { - - public HotSpotCurrentRawThreadNode() { - super(StampFactory.forWord()); - } - - @Override - public void generate(LIRGeneratorTool gen) { - Register rawThread = HotSpotGraalRuntime.getInstance().getRuntime().threadRegister(); - gen.setResult(this, rawThread.asValue(this.kind())); - } - - @NodeIntrinsic - public static native Word get(); -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/IdentityHashCodeStubCall.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/IdentityHashCodeStubCall.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/IdentityHashCodeStubCall.java Thu Mar 28 12:58:50 2013 +0100 @@ -52,5 +52,7 @@ } @NodeIntrinsic - public static native int call(Object object); + public static int call(Object object) { + return System.identityHashCode(object); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeArrayNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeArrayNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeArrayNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.nodes; import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; @@ -72,7 +73,9 @@ } public boolean fillContents() { - return fillContents; + // We fill contents when G1 GC is used since we want to record + // the original field values prior to stores + return HotSpotSnippetUtils.useG1GC() ? true : fillContents; } public boolean locked() { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeObjectNode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeObjectNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/InitializeObjectNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -23,6 +23,7 @@ package com.oracle.graal.hotspot.nodes; import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.replacements.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; @@ -56,7 +57,7 @@ } public boolean fillContents() { - return fillContents; + return HotSpotSnippetUtils.useG1GC() ? true : fillContents; } public boolean locked() { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/SerialWriteBarrierPost.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/SerialWriteBarrierPost.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; + +public class SerialWriteBarrierPost extends WriteBarrierPost implements Lowerable { + + @Input private ValueNode object; + @Input private LocationNode location; + private final boolean usePrecise; + + public SerialWriteBarrierPost(ValueNode object, LocationNode location, boolean usePrecise) { + this.object = object; + this.location = location; + this.usePrecise = usePrecise; + } + + @Override + public ValueNode getObject() { + return object; + } + + @Override + public LocationNode getLocation() { + return location; + } + + @Override + public boolean usePrecise() { + return usePrecise; + } + + @Override + public void lower(LoweringTool generator) { + generator.getRuntime().lower(this, generator); + } + +} diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/ThreadIsInterruptedStubCall.java Thu Mar 28 12:58:50 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 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrier.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,10 +22,7 @@ */ package com.oracle.graal.hotspot.nodes; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.hotspot.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; public abstract class WriteBarrier extends FixedWithNextNode { @@ -34,17 +31,4 @@ super(StampFactory.forVoid()); } - protected void generateBarrier(Value adr, LIRGeneratorTool gen) { - HotSpotVMConfig config = HotSpotGraalRuntime.getInstance().getConfig(); - Value base = gen.emitUShr(adr, Constant.forInt(config.cardtableShift)); - - long startAddress = config.cardtableStartAddress; - int displacement = 0; - if (((int) startAddress) == startAddress) { - displacement = (int) startAddress; - } else { - base = gen.emitAdd(base, Constant.forLong(config.cardtableStartAddress)); - } - gen.emitStore(Kind.Boolean, base, displacement, Value.ILLEGAL, 0, Constant.FALSE, false); - } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPost.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPost.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; + +public class WriteBarrierPost extends WriteBarrier implements Lowerable { + + @Input private ValueNode object; + @Input private ValueNode value; + @Input private ValueNode index; + @Input private LocationNode location; + private final boolean precise; + + public ValueNode getObject() { + return object; + } + + public ValueNode getValue() { + return value; + } + + public LocationNode getLocation() { + return location; + } + + public boolean usePrecise() { + return precise; + } + + public WriteBarrierPost() { + this.precise = false; + } + + public WriteBarrierPost(ValueNode object, ValueNode value, ValueNode index) { + this.object = object; + this.value = value; + this.index = index; + this.precise = true; + this.location = null; + } + + public WriteBarrierPost(ValueNode object, ValueNode value, LocationNode location, boolean precise) { + this.object = object; + this.value = value; + this.location = location; + this.precise = precise; + } + + @Override + public void lower(LoweringTool generator) { + StructuredGraph graph = (StructuredGraph) this.graph(); + if (location == null) { // Come from array copy intrinsic + LocationNode arrayLocation = IndexedLocationNode.create(LocationNode.getArrayLocation(Kind.Object), Kind.Object, arrayBaseOffset(Kind.Object), index, graph, arrayIndexScale(Kind.Object)); + if (useG1GC()) { + graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPost(object, value, arrayLocation, true))); + } else { + graph.replaceFixedWithFixed(this, graph().add(new SerialWriteBarrierPost(object, arrayLocation, true))); + } + } else { // Normal WriteBarrier + assert location != null; + if (useG1GC()) { + graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPost(object, value, location, precise))); + } else { + graph.replaceFixedWithFixed(this, graph().add(new SerialWriteBarrierPost(object, location, precise))); + } + } + } + + @NodeIntrinsic + public static native void arrayCopyWriteBarrier(Object array, Object value, int index); +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPostStubCall.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPostStubCall.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; +import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.target.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; +import com.oracle.graal.word.*; + +/** + * Node implementing a call to HotSpot's {@code graal_monitorenter} stub. + */ +public class WriteBarrierPostStubCall extends FixedWithNextNode implements LIRGenLowerable { + + @Input private ValueNode object; + @Input private ValueNode card; + public static final Descriptor WBPOSTCALL = new Descriptor("wbpostcall", true, void.class, Object.class, Word.class); + + public WriteBarrierPostStubCall(ValueNode object, ValueNode card) { + super(StampFactory.forVoid()); + this.object = object; + this.card = card; + } + + @Override + public void generate(LIRGenerator gen) { + RuntimeCallTarget stub = gen.getRuntime().lookupRuntimeCall(WriteBarrierPostStubCall.WBPOSTCALL); + gen.emitCall(stub, stub.getCallingConvention(), false, gen.operand(object), gen.operand(card)); + } + + @NodeIntrinsic + public static native void call(Object hub, Word card); +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPre.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPre.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*; + +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.spi.*; + +public class WriteBarrierPre extends WriteBarrier implements Lowerable { + + @Input private ValueNode object; + @Input private LocationNode location; + @Input private ValueNode expectedObject; + private final boolean doLoad; + + public ValueNode getObject() { + return object; + } + + public ValueNode getExpectedObject() { + return expectedObject; + } + + public boolean doLoad() { + return doLoad; + } + + public LocationNode getLocation() { + return location; + } + + public WriteBarrierPre() { + this.doLoad = false; + } + + public WriteBarrierPre(ValueNode object, ValueNode expectedObject, LocationNode location, boolean doLoad) { + this.object = object; + this.doLoad = doLoad; + this.location = location; + this.expectedObject = expectedObject; + } + + @Override + public void lower(LoweringTool generator) { + StructuredGraph graph = (StructuredGraph) this.graph(); + if (useG1GC()) { + graph.replaceFixedWithFixed(this, graph().add(new G1WriteBarrierPre(getObject(), getExpectedObject(), getLocation(), doLoad()))); + } else { + graph.removeFixed(this); + } + } + +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPreStubCall.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/nodes/WriteBarrierPreStubCall.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.nodes; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.code.RuntimeCallTarget.Descriptor; +import com.oracle.graal.compiler.gen.*; +import com.oracle.graal.compiler.target.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.type.*; + +/** + * Node implementing a call to HotSpot's {@code graal_monitorenter} stub. + */ +public class WriteBarrierPreStubCall extends FixedWithNextNode implements LIRGenLowerable { + + @Input private ValueNode object; + public static final Descriptor WBPRECALL = new Descriptor("wbprecall", true, void.class, Object.class); + + public WriteBarrierPreStubCall(ValueNode object) { + super(StampFactory.forVoid()); + this.object = object; + } + + @Override + public void generate(LIRGenerator gen) { + RuntimeCallTarget stub = gen.getRuntime().lookupRuntimeCall(WriteBarrierPreStubCall.WBPRECALL); + gen.emitCall(stub, stub.getCallingConvention(), false, gen.operand(object)); + } + + @NodeIntrinsic + public static native void call(Object hub); +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/OnStackReplacementPhase.java Thu Mar 28 12:58:50 2013 +0100 @@ -82,8 +82,7 @@ throw new BailoutException("No OnStackReplacementNode generated"); } if (osrNodes.count() > 1) { - // this can happen with JSR inlining - throw new BailoutException("Multiple OnStackReplacementNodes generated"); + throw new GraalInternalError("Multiple OnStackReplacementNodes generated"); } if (osr.stateAfter().locksSize() != 0) { throw new BailoutException("OSR with locks not supported"); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ArrayCopySnippets.java Thu Mar 28 12:58:50 2013 +0100 @@ -37,7 +37,7 @@ import com.oracle.graal.nodes.java.*; import com.oracle.graal.phases.*; import com.oracle.graal.replacements.*; -import com.oracle.graal.replacements.Snippet.*; +import com.oracle.graal.replacements.Snippet.ConstantParameter; import com.oracle.graal.replacements.nodes.*; import com.oracle.graal.word.*; @@ -236,9 +236,8 @@ } } - // Does NOT perform store checks @Snippet - public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) { + private static void arrayObjectCopy(Object src, int srcPos, Object dest, int destPos, int length) { objectCounter.inc(); checkNonNull(src); checkNonNull(dest); @@ -247,44 +246,49 @@ int header = arrayBaseOffset(Kind.Object); if (src == dest && srcPos < destPos) { // bad aliased case long start = (long) (length - 1) * scale; + int j = length - 1; for (long i = start; i >= 0; i -= scale) { Object a = UnsafeLoadNode.load(src, header, i + (long) srcPos * scale, Kind.Object); DirectObjectStoreNode.storeObject(dest, header, i + (long) destPos * scale, a); + WriteBarrierPost.arrayCopyWriteBarrier(dest, a, j); + j--; } } else { long end = (long) length * scale; + int j = 0; for (long i = 0; i < end; i += scale) { Object a = UnsafeLoadNode.load(src, header, i + (long) srcPos * scale, Kind.Object); DirectObjectStoreNode.storeObject(dest, header, i + (long) destPos * scale, a); - } - } - if (length > 0) { - int cardShift = cardTableShift(); - long cardStart = cardTableStart(); - long dstAddr = GetObjectAddressNode.get(dest); - long start = (dstAddr + header + (long) destPos * scale) >>> cardShift; - long end = (dstAddr + header + ((long) destPos + length - 1) * scale) >>> cardShift; - long count = end - start + 1; - while (count-- > 0) { - DirectStoreNode.store((start + cardStart) + count, false, Kind.Boolean); + WriteBarrierPost.arrayCopyWriteBarrier(dest, a, j); + j++; } } } + // Does NOT perform store checks + @Snippet + public static void arraycopy(Object[] src, int srcPos, Object[] dest, int destPos, int length) { + arrayObjectCopy(src, srcPos, dest, destPos, length); + } + @Snippet public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) { - - // loading the hubs also checks for nullness Word srcHub = loadHub(src); Word destHub = loadHub(dest); - int layoutHelper = checkArrayType(srcHub); + int log2ElementSize = (layoutHelper >> layoutHelperLog2ElementSizeShift()) & layoutHelperLog2ElementSizeMask(); + final boolean isObjectArray = ((layoutHelper & layoutHelperElementTypePrimitiveInPlace()) == 0); if (srcHub.equal(destHub) && src != dest) { probability(FAST_PATH_PROBABILITY); - checkLimits(src, srcPos, dest, destPos, length); - - arraycopyInnerloop(src, srcPos, dest, destPos, length, layoutHelper); + if (isObjectArray) { + genericObjectExactCallCounter.inc(); + probability(FAST_PATH_PROBABILITY); + arrayObjectCopy(src, srcPos, dest, destPos, length); + } else { + genericPrimitiveCallCounter.inc(); + arraycopyInnerloop(src, srcPos, dest, destPos, length, layoutHelper); + } } else { genericObjectCallCounter.inc(); System.arraycopy(src, srcPos, dest, destPos, length); @@ -312,29 +316,11 @@ srcOffset = srcOffset.add(1); } while (destOffset.belowThan(destEnd)) { - destOffset.writeWord(0, srcOffset.readWord(0, UNKNOWN_LOCATION), ANY_LOCATION); + Word word = srcOffset.readWord(0, UNKNOWN_LOCATION); + destOffset.writeWord(0, word, ANY_LOCATION); destOffset = destOffset.add(wordSize()); srcOffset = srcOffset.add(wordSize()); } - - if ((layoutHelper & layoutHelperElementTypePrimitiveInPlace()) != 0) { - genericPrimitiveCallCounter.inc(); - - } else { - probability(LIKELY_PROBABILITY); - genericObjectExactCallCounter.inc(); - - if (length > 0) { - int cardShift = cardTableShift(); - long cardStart = cardTableStart(); - Word destCardOffset = destStart.unsignedShiftRight(cardShift).add(Word.unsigned(cardStart)); - Word destCardEnd = destEnd.subtract(1).unsignedShiftRight(cardShift).add(Word.unsigned(cardStart)); - while (destCardOffset.belowOrEqual(destCardEnd)) { - DirectStoreNode.store(destCardOffset.rawValue(), false, Kind.Boolean); - destCardOffset = destCardOffset.add(1); - } - } - } } private static final SnippetCounter.Group checkCounters = GraalOptions.SnippetCounters ? new SnippetCounter.Group("System.arraycopy checkInputs") : null; diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CheckCastSnippets.java Thu Mar 28 12:58:50 2013 +0100 @@ -81,7 +81,11 @@ } exactHit.inc(); } - return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); + /** + * make sure that the unsafeCast is done *after* the check above, + * cf. {@link ReadAfterCheckCast}*/ + BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic()); + return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic(), anchorNode); } /** @@ -109,7 +113,8 @@ } displayHit.inc(); } - return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); + BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic()); + return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic(), anchorNode); } /** @@ -132,14 +137,16 @@ Word hintHub = hints[i]; if (hintHub.equal(objectHub)) { hintsHit.inc(); - return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); + BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic()); + return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic(), anchorNode); } } if (!checkSecondarySubType(hub, objectHub)) { DeoptimizeNode.deopt(InvalidateReprofile, ClassCastException); } } - return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); + BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic()); + return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic(), anchorNode); } /** @@ -160,7 +167,8 @@ DeoptimizeNode.deopt(InvalidateReprofile, ClassCastException); } } - return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); + BeginNode anchorNode = BeginNode.anchor(StampFactory.forNodeIntrinsic()); + return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic(), anchorNode); } // @formatter:on diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotSnippetUtils.java Thu Mar 28 12:58:50 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.*; @@ -53,6 +54,11 @@ } @Fold + public static boolean useTLAB() { + return config().useTLAB; + } + + @Fold public static boolean verifyOops() { return config().verifyOops; } @@ -281,6 +287,36 @@ } @Fold + public static int g1CardQueueIndexOffset() { + return config().g1CardQueueIndexOffset; + } + + @Fold + public static int g1CardQueueBufferOffset() { + return config().g1CardQueueBufferOffset; + } + + @Fold + public static int logOfHRGrainBytes() { + return config().logOfHRGrainBytes; + } + + @Fold + public static int g1SATBQueueMarkingOffset() { + return config().g1SATBQueueMarkingOffset; + } + + @Fold + public static int g1SATBQueueIndexOffset() { + return config().g1SATBQueueIndexOffset; + } + + @Fold + public static int g1SATBQueueBufferOffset() { + return config().g1SATBQueueBufferOffset; + } + + @Fold public static int superCheckOffsetOffset() { return config().superCheckOffsetOffset; } @@ -312,6 +348,11 @@ } @Fold + public static boolean useG1GC() { + return config().useG1GC; + } + + @Fold static int uninitializedIdentityHashCodeValue() { return config().uninitializedIdentityHashCodeValue; } @@ -356,11 +397,17 @@ @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)); + } + @SuppressWarnings("unused") @NodeIntrinsic(value = LoadHubNode.class, setStampFromReturnType = true) - static native Word loadHubIntrinsic(Object object, @ConstantNodeParameter Kind word); + static Word loadHubIntrinsic(Object object, @ConstantNodeParameter Kind word) { + return Word.box(unsafeReadWord(object, hubOffset())); + } @Fold public static int log2WordSize() { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectSubstitutions.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ObjectSubstitutions.java Thu Mar 28 12:58:50 2013 +0100 @@ -27,6 +27,7 @@ import com.oracle.graal.api.replacements.*; import com.oracle.graal.nodes.extended.*; +import com.oracle.graal.nodes.java.*; import com.oracle.graal.replacements.*; import com.oracle.graal.word.*; @@ -47,6 +48,11 @@ return computeHashCode(thisObj); } + @MethodSubstitution(value = "", isStatic = false) + public static void init(Object thisObj) { + RegisterFinalizerNode.register(thisObj); + } + @MacroSubstitution(macro = ObjectCloneNode.class, isStatic = false) public static native Object clone(Object obj); } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/SystemSubstitutions.java diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ThreadSubstitutions.java Thu Mar 28 12:58:50 2013 +0100 @@ -23,7 +23,6 @@ package com.oracle.graal.hotspot.replacements; import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*; -import static com.oracle.graal.nodes.extended.UnsafeCastNode.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.hotspot.nodes.*; @@ -37,25 +36,21 @@ @MethodSubstitution public static Thread currentThread() { - return CurrentThread.get(); + return (Thread) CurrentJavaThreadNode.get().readObject(threadObjectOffset(), FINAL_LOCATION); } - @Alias(declaringClass = Thread.class) private long eetop; - @MethodSubstitution(isStatic = false) public static boolean isInterrupted(final Thread thisObject, boolean clearInterrupted) { - Thread thread = CurrentThread.get(); + Word javaThread = CurrentJavaThreadNode.get(); + Object thread = javaThread.readObject(threadObjectOffset(), FINAL_LOCATION); if (thisObject == thread) { - ThreadSubstitutions threadAlias = unsafeCast(thread, ThreadSubstitutions.class, false, true); - Word rawThread = Word.unsigned(threadAlias.eetop); - Word osThread = rawThread.readWord(osThreadOffset(), FINAL_LOCATION); - int int0 = osThread.readInt(osThreadInterruptedOffset(), UNKNOWN_LOCATION); - boolean interrupted = int0 != 0; + Word osThread = javaThread.readWord(osThreadOffset(), FINAL_LOCATION); + 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 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/WriteBarrierSnippets.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2012, 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.graal.hotspot.replacements; + +import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*; +import static com.oracle.graal.replacements.SnippetTemplate.*; + +import com.oracle.graal.api.code.*; +import com.oracle.graal.api.meta.*; +import com.oracle.graal.hotspot.nodes.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.replacements.*; +import com.oracle.graal.replacements.Snippet.ConstantParameter; +import com.oracle.graal.replacements.Snippet.Parameter; +import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates; +import com.oracle.graal.replacements.SnippetTemplate.Arguments; +import com.oracle.graal.replacements.SnippetTemplate.Key; +import com.oracle.graal.word.*; + +public class WriteBarrierSnippets implements Snippets { + + @Snippet + public static void g1WriteBarrierPre(@Parameter("object") Object obj, @Parameter("expectedObject") Object expobj, @Parameter("location") Object location, + @ConstantParameter("doLoad") boolean doLoad) { + Word thread = thread(); + Object object = FixedValueAnchorNode.getObject(obj); + Object expectedObject = FixedValueAnchorNode.getObject(expobj); + Word field = (Word) Word.fromArray(object, location); + Word previousOop = (Word) Word.fromObject(expectedObject); + byte markingValue = thread.readByte(HotSpotSnippetUtils.g1SATBQueueMarkingOffset()); + Word bufferAddress = thread.readWord(HotSpotSnippetUtils.g1SATBQueueBufferOffset()); + Word indexAddress = thread.add(HotSpotSnippetUtils.g1SATBQueueIndexOffset()); + Word indexValue = indexAddress.readWord(0); + if (markingValue != (byte) 0) { + if (doLoad) { + previousOop = field.readWord(0); + } + if (previousOop.notEqual(Word.zero())) { + if (indexValue.notEqual(Word.zero())) { + Word nextIndex = indexValue.subtract(HotSpotSnippetUtils.wordSize()); + Word logAddress = bufferAddress.add(nextIndex); + logAddress.writeWord(0, previousOop); + indexAddress.writeWord(0, nextIndex); + } else { + WriteBarrierPreStubCall.call(previousOop); + } + } + } + } + + @Snippet + public static void g1WriteBarrierPost(@Parameter("object") Object obj, @Parameter("value") Object value, @Parameter("location") Object location, @ConstantParameter("usePrecise") boolean usePrecise) { + Word thread = thread(); + Object object = FixedValueAnchorNode.getObject(obj); + Object wrObject = FixedValueAnchorNode.getObject(value); + Word oop = (Word) Word.fromObject(object); + Word field; + if (usePrecise) { + field = (Word) Word.fromArray(object, location); + } else { + field = oop; + } + Word writtenValue = (Word) Word.fromObject(wrObject); + Word bufferAddress = thread.readWord(HotSpotSnippetUtils.g1CardQueueBufferOffset()); + Word indexAddress = thread.add(HotSpotSnippetUtils.g1CardQueueIndexOffset()); + Word indexValue = thread.readWord(HotSpotSnippetUtils.g1CardQueueIndexOffset()); + Word xorResult = (field.xor(writtenValue)).unsignedShiftRight(HotSpotSnippetUtils.logOfHRGrainBytes()); + + // Card Table + Word cardBase = field.unsignedShiftRight(cardTableShift()); + long startAddress = cardTableStart(); + int displacement = 0; + if (((int) startAddress) == startAddress) { + displacement = (int) startAddress; + } else { + cardBase = cardBase.add(Word.unsigned(cardTableStart())); + } + Word cardAddress = cardBase.add(displacement); + if (xorResult.notEqual(Word.zero())) { + if (writtenValue.notEqual(Word.zero())) { + byte cardByte = cardAddress.readByte(0); + if (cardByte != (byte) 0) { + cardAddress.writeByte(0, (byte) 0); // smash zero into card + if (indexValue.notEqual(Word.zero())) { + Word nextIndex = indexValue.subtract(HotSpotSnippetUtils.wordSize()); + Word logAddress = bufferAddress.add(nextIndex); + logAddress.writeWord(0, cardAddress); + indexAddress.writeWord(0, nextIndex); + } else { + WriteBarrierPostStubCall.call(object, cardAddress); + } + } + } + } + } + + @Snippet + public static void serialWriteBarrierPost(@Parameter("object") Object obj, @Parameter("location") Object location, @ConstantParameter("usePrecise") boolean usePrecise) { + Object object = FixedValueAnchorNode.getObject(obj); + Pointer oop; + if (usePrecise) { + oop = Word.fromArray(object, location); + } else { + oop = Word.fromObject(object); + } + Word base = (Word) oop.unsignedShiftRight(cardTableShift()); + long startAddress = cardTableStart(); + int displacement = 0; + if (((int) startAddress) == startAddress) { + displacement = (int) startAddress; + } else { + base = base.add(Word.unsigned(cardTableStart())); + } + base.writeByte(displacement, (byte) 0); + } + + public static class Templates extends AbstractTemplates { + + private final ResolvedJavaMethod serialWriteBarrierPost; + private final ResolvedJavaMethod g1WriteBarrierPre; + private final ResolvedJavaMethod g1WriteBarrierPost; + + public Templates(CodeCacheProvider runtime, Assumptions assumptions, TargetDescription target) { + super(runtime, assumptions, target, WriteBarrierSnippets.class); + serialWriteBarrierPost = snippet("serialWriteBarrierPost", Object.class, Object.class, boolean.class); + g1WriteBarrierPre = snippet("g1WriteBarrierPre", Object.class, Object.class, Object.class, boolean.class); + g1WriteBarrierPost = snippet("g1WriteBarrierPost", Object.class, Object.class, Object.class, boolean.class); + } + + public void lower(SerialWriteBarrierPost fieldWriteBarrier, @SuppressWarnings("unused") LoweringTool tool) { + ResolvedJavaMethod method = serialWriteBarrierPost; + Key key = new Key(method); + key.add("usePrecise", fieldWriteBarrier.usePrecise()); + Arguments arguments = new Arguments(); + arguments.add("object", fieldWriteBarrier.getObject()); + arguments.add("location", fieldWriteBarrier.getLocation()); + SnippetTemplate template = cache.get(key, assumptions); + template.instantiate(runtime, fieldWriteBarrier, DEFAULT_REPLACER, arguments); + } + + public void lower(G1WriteBarrierPre writeBarrierPre, @SuppressWarnings("unused") LoweringTool tool) { + ResolvedJavaMethod method = g1WriteBarrierPre; + Key key = new Key(method); + key.add("doLoad", writeBarrierPre.doLoad()); + Arguments arguments = new Arguments(); + arguments.add("object", writeBarrierPre.getObject()); + arguments.add("expectedObject", writeBarrierPre.getExpectedObject()); + arguments.add("location", writeBarrierPre.getLocation()); + SnippetTemplate template = cache.get(key, assumptions); + template.instantiate(runtime, writeBarrierPre, DEFAULT_REPLACER, arguments); + } + + public void lower(G1WriteBarrierPost writeBarrierPost, @SuppressWarnings("unused") LoweringTool tool) { + ResolvedJavaMethod method = g1WriteBarrierPost; + Key key = new Key(method); + key.add("usePrecise", writeBarrierPost.usePrecise()); + Arguments arguments = new Arguments(); + arguments.add("object", writeBarrierPost.getObject()); + arguments.add("location", writeBarrierPost.getLocation()); + arguments.add("value", writeBarrierPost.getValue()); + SnippetTemplate template = cache.get(key, assumptions); + template.instantiate(runtime, writeBarrierPost, DEFAULT_REPLACER, arguments); + } + + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Thu Mar 28 12:58:50 2013 +0100 @@ -92,7 +92,12 @@ * operation was unsuccessful */ static Word refillAllocate(Word intArrayHub, int sizeInBytes, boolean log) { - + if (useG1GC()) { + return Word.zero(); + } + if (!useTLAB()) { + return edenAllocate(Word.unsigned(sizeInBytes), log); + } Word intArrayMarkWord = Word.unsigned(tlabIntArrayMarkWord()); int alignmentReserveInBytes = tlabAlignmentReserveInHeapWords() * wordSize(); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/BciBlockMapping.java Thu Mar 28 12:58:50 2013 +0100 @@ -782,14 +782,6 @@ stream.setBCI(block.startBci); while (stream.currentBCI() <= block.endBci) { switch (stream.currentBC()) { - case RETURN: - if (method.isConstructor() && MetaUtil.isJavaLangObject(method.getDeclaringClass())) { - // return from Object.init implicitly registers a finalizer - // for the receiver if needed, so keep it alive. - loadOne(block, 0); - } - break; - case LLOAD: case DLOAD: loadTwo(block, stream.readLocalIndex()); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java Thu Mar 28 12:58:50 2013 +0100 @@ -745,7 +745,8 @@ private JavaMethod lookupMethod(int cpi, int opcode) { eagerResolvingForSnippets(cpi, opcode); JavaMethod result = constantPool.lookupMethod(cpi, opcode); - assert !graphBuilderConfig.unresolvedIsError() || ((result instanceof ResolvedJavaMethod) && ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized()) : result; + // assert !graphBuilderConfig.unresolvedIsError() || ((result instanceof ResolvedJavaMethod) +// && ((ResolvedJavaMethod) result).getDeclaringClass().isInitialized()) : result; return result; } @@ -1143,11 +1144,6 @@ } } - private void callRegisterFinalizer() { - // append a call to the finalizer registration - append(currentGraph.add(new RegisterFinalizerNode(frameState.loadLocal(0)))); - } - private void genReturn(ValueNode x) { frameState.clearStack(); if (x != null) { @@ -1562,9 +1558,6 @@ } private void createReturn() { - if (method.isConstructor() && MetaUtil.isJavaLangObject(method.getDeclaringClass())) { - callRegisterFinalizer(); - } Kind returnKind = method.getSignature().getReturnKind().getStackKind(); ValueNode x = returnKind == Kind.Void ? null : frameState.pop(returnKind); assert frameState.stackSize() == 0; @@ -1695,6 +1688,9 @@ traceState(); traceInstruction(bci, opcode, bci == block.startBci); if (bci == entryBCI) { + if (block.jsrScope != JsrScope.EMPTY_SCOPE) { + throw new BailoutException("OSR into a JSR scope is not supported"); + } EntryMarkerNode x = currentGraph.add(new EntryMarkerNode()); append(x); frameState.insertProxies(x); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/BeginNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -184,4 +184,7 @@ throw new UnsupportedOperationException(); } } + + @NodeIntrinsic + public static native T anchor(@ConstantNodeParameter Stamp stamp); } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/InvokeNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/InvokeNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/InvokeNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -160,20 +160,15 @@ StateSplit stateSplit = (StateSplit) node; stateSplit.setStateAfter(stateAfter); } - if (node == null) { - assert kind() == Kind.Void && usages().isEmpty(); - ((StructuredGraph) graph()).removeFixed(this); + if (node instanceof FixedWithNextNode) { + ((StructuredGraph) graph()).replaceFixedWithFixed(this, (FixedWithNextNode) node); + } else if (node instanceof DeoptimizeNode) { + this.replaceAtPredecessor(node); + this.replaceAtUsages(null); + GraphUtil.killCFG(this); + return; } else { - if (node instanceof FixedWithNextNode) { - ((StructuredGraph) graph()).replaceFixedWithFixed(this, (FixedWithNextNode) node); - } else if (node instanceof DeoptimizeNode) { - this.replaceAtPredecessor(node); - this.replaceAtUsages(null); - GraphUtil.killCFG(this); - return; - } else { - ((StructuredGraph) graph()).replaceFixed(this, node); - } + ((StructuredGraph) graph()).replaceFixed(this, node); } call.safeDelete(); if (stateAfter.usages().isEmpty()) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -115,5 +115,7 @@ public static native boolean materializeCondition(@ConstantNodeParameter Condition condition, long x, long y); @NodeIntrinsic - public static native boolean materializeIsInstance(Class mirror, Object object); + public static boolean materializeIsInstance(Class mirror, Object object) { + return mirror.isInstance(object); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ComputeAddressNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ComputeAddressNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009, 2011, 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.graal.nodes.extended; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.spi.*; +import com.oracle.graal.nodes.type.*; + +public class ComputeAddressNode extends FloatingNode implements LIRLowerable { + + @Input private ValueNode object; + @Input private ValueNode location; + + public ValueNode getObject() { + return object; + } + + public LocationNode getLocation() { + return (LocationNode) location; + } + + public ComputeAddressNode(ValueNode object, ValueNode location, Stamp stamp) { + super(stamp); + this.object = object; + this.location = location; + } + + @Override + public void generate(LIRGeneratorTool gen) { + Value addr = getLocation().generateLea(gen, getObject()); + gen.setResult(this, addr); + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/MembarNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,7 +22,14 @@ */ package com.oracle.graal.nodes.extended; +import static com.oracle.graal.graph.UnsafeAccess.*; + +import java.lang.reflect.*; + +import sun.misc.*; + import com.oracle.graal.api.code.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.type.*; @@ -52,6 +59,28 @@ generator.emitMembar(barriers); } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void memoryBarrier(@ConstantNodeParameter int barriers); + public static void memoryBarrier(@ConstantNodeParameter int barriers) { + // Overly conservative but it doesn't matter in the interpreter + unsafe.putIntVolatile(dummyBase, dummyOffset, 0); + unsafe.getIntVolatile(dummyBase, dummyOffset); + } + + /** + * An unused field that it used to exercise barriers in the interpreter. This can be replaced + * with direct support for barriers in {@link Unsafe} if/when they become available. + */ + @SuppressWarnings("unused") private static int dummy; + private static Object dummyBase; + private static long dummyOffset; + static { + try { + Field dummyField = MembarNode.class.getDeclaredField("dummy"); + dummyBase = unsafe.staticFieldBase(dummyField); + dummyOffset = unsafe.staticFieldOffset(dummyField); + } catch (Exception e) { + throw new GraalInternalError(e); + } + } } diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeCastNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -44,6 +44,11 @@ this.object = object; } + public UnsafeCastNode(ValueNode object, Stamp stamp, ValueNode anchor) { + super(stamp, anchor); + this.object = object; + } + public UnsafeCastNode(ValueNode object, ResolvedJavaType toType, boolean exactType, boolean nonNull) { this(object, toType.getKind() == Kind.Object ? StampFactory.object(toType, exactType, nonNull || object.stamp().nonNull()) : StampFactory.forKind(toType.getKind())); } @@ -110,5 +115,11 @@ public static native T unsafeCast(Object object, @ConstantNodeParameter Stamp stamp); @NodeIntrinsic - public static native T unsafeCast(Object object, @ConstantNodeParameter Class toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull); + public static native T unsafeCast(Object object, @ConstantNodeParameter Stamp stamp, ValueNode anchor); + + @SuppressWarnings("unused") + @NodeIntrinsic + public static T unsafeCast(Object object, @ConstantNodeParameter Class toType, @ConstantNodeParameter boolean exactType, @ConstantNodeParameter boolean nonNull) { + return toType.cast(object); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeLoadNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeLoadNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeLoadNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.nodes.extended; +import static com.oracle.graal.graph.UnsafeAccess.*; + import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; @@ -93,6 +95,34 @@ return this; } + @SuppressWarnings("unchecked") @NodeIntrinsic - public static native T load(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind kind); + public static T load(Object object, @ConstantNodeParameter int displacement, long offset, @ConstantNodeParameter Kind kind) { + if (kind == Kind.Boolean) { + return (T) (Boolean) unsafe.getBoolean(object, displacement + offset); + } + if (kind == Kind.Byte) { + return (T) (Byte) unsafe.getByte(object, displacement + offset); + } + if (kind == Kind.Short) { + return (T) (Short) unsafe.getShort(object, displacement + offset); + } + if (kind == Kind.Char) { + return (T) (Character) unsafe.getChar(object, displacement + offset); + } + if (kind == Kind.Int) { + return (T) (Integer) unsafe.getInt(object, displacement + offset); + } + if (kind == Kind.Float) { + return (T) (Float) unsafe.getFloat(object, displacement + offset); + } + if (kind == Kind.Long) { + return (T) (Long) unsafe.getLong(object, displacement + offset); + } + if (kind == Kind.Double) { + return (T) (Double) unsafe.getDouble(object, displacement + offset); + } + assert kind == Kind.Object; + return (T) unsafe.getObject(object, displacement + offset); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeStoreNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeStoreNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/UnsafeStoreNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.nodes.extended; +import static com.oracle.graal.graph.UnsafeAccess.*; + import com.oracle.graal.api.meta.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; @@ -119,31 +121,58 @@ } // specialized on value type until boxing/unboxing is sorted out in intrinsification - @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, Object value, @ConstantNodeParameter Kind kind); + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, boolean value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, Object value, @ConstantNodeParameter Kind kind) { + unsafe.putObject(object, offset + displacement, value); + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, boolean value, @ConstantNodeParameter Kind kind) { + unsafe.putBoolean(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, byte value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, byte value, @ConstantNodeParameter Kind kind) { + unsafe.putByte(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, char value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, char value, @ConstantNodeParameter Kind kind) { + unsafe.putChar(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, double value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, double value, @ConstantNodeParameter Kind kind) { + unsafe.putDouble(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, float value, @ConstantNodeParameter Kind kind); - - @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, int value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, float value, @ConstantNodeParameter Kind kind) { + unsafe.putFloat(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, long value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, int value, @ConstantNodeParameter Kind kind) { + unsafe.putInt(object, offset + displacement, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(Object object, @ConstantNodeParameter int displacement, long offset, short value, @ConstantNodeParameter Kind kind); + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, long value, @ConstantNodeParameter Kind kind) { + unsafe.putLong(object, offset + displacement, value); + } + @SuppressWarnings("unused") + @NodeIntrinsic + public static void store(Object object, @ConstantNodeParameter int displacement, long offset, short value, @ConstantNodeParameter Kind kind) { + unsafe.putShort(object, offset + displacement, value); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/CompareAndSwapNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.nodes.java; +import static com.oracle.graal.graph.UnsafeAccess.*; + import com.oracle.graal.api.meta.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; @@ -87,11 +89,17 @@ // specialized on value type until boxing/unboxing is sorted out in intrinsification @NodeIntrinsic - public static native boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, Object expected, Object newValue); + public static boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, Object expected, Object newValue) { + return unsafe.compareAndSwapObject(object, displacement + offset, expected, newValue); + } @NodeIntrinsic - public static native boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, long expected, long newValue); + public static boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, long expected, long newValue) { + return unsafe.compareAndSwapLong(object, displacement + offset, expected, newValue); + } @NodeIntrinsic - public static native boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, int expected, int newValue); + public static boolean compareAndSwap(Object object, @ConstantNodeParameter int displacement, long offset, int expected, int newValue) { + return unsafe.compareAndSwapInt(object, displacement + offset, expected, newValue); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/RegisterFinalizerNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -61,8 +61,8 @@ if (stamp.isExactType()) { needsCheck = stamp.type().hasFinalizer(); } else if (stamp.type() != null && !stamp.type().hasFinalizableSubclass()) { - // if either the declared type of receiver or the holder can be assumed to have no - // finalizers + // if either the declared type of receiver or the holder + // can be assumed to have no finalizers if (tool.assumptions().useOptimisticAssumptions() && tool.assumptions().recordNoFinalizableSubclassAssumption(stamp.type())) { needsCheck = false; } @@ -82,4 +82,9 @@ tool.delete(); } } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void register(Object thisObj) { + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/IterativeConditionalEliminationPhase.java diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/PostOrderNodeIterator.java diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/MethodSubstitutionTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/MethodSubstitutionTest.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/MethodSubstitutionTest.java Thu Mar 28 12:58:50 2013 +0100 @@ -26,296 +26,21 @@ import java.util.concurrent.*; -import org.junit.*; - -import sun.misc.*; - import com.oracle.graal.api.code.*; import com.oracle.graal.api.replacements.*; import com.oracle.graal.compiler.test.*; import com.oracle.graal.debug.*; import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.calc.*; import com.oracle.graal.phases.*; import com.oracle.graal.phases.common.*; -import com.oracle.graal.replacements.nodes.*; /** * Tests if {@link MethodSubstitution}s are inlined correctly. Most test cases only assert that * there are no remaining invocations in the graph. This is sufficient if the method that is being * substituted is a native method. For Java methods, additional checks are necessary. */ -public class MethodSubstitutionTest extends GraalCompilerTest { - - @Test - public void testUnsafeSubstitutions() { - test("unsafeCompareAndSwapInt"); - test("unsafeCompareAndSwapLong"); - test("unsafeCompareAndSwapObject"); - - test("unsafeGetBoolean"); - test("unsafeGetByte"); - test("unsafeGetShort"); - test("unsafeGetChar"); - test("unsafeGetInt"); - test("unsafeGetFloat"); - test("unsafeGetDouble"); - test("unsafeGetObject"); - - test("unsafePutBoolean"); - test("unsafePutByte"); - test("unsafePutShort"); - test("unsafePutChar"); - test("unsafePutInt"); - test("unsafePutFloat"); - test("unsafePutDouble"); - test("unsafePutObject"); - - test("unsafeDirectMemoryRead"); - test("unsafeDirectMemoryWrite"); - } - - @SuppressWarnings("all") - public static boolean unsafeCompareAndSwapInt(Unsafe unsafe, Object obj, long offset) { - return unsafe.compareAndSwapInt(obj, offset, 0, 1); - } - - @SuppressWarnings("all") - public static boolean unsafeCompareAndSwapLong(Unsafe unsafe, Object obj, long offset) { - return unsafe.compareAndSwapLong(obj, offset, 0, 1); - } - - @SuppressWarnings("all") - public static boolean unsafeCompareAndSwapObject(Unsafe unsafe, Object obj, long offset) { - return unsafe.compareAndSwapObject(obj, offset, null, new Object()); - } - - @SuppressWarnings("all") - public static boolean unsafeGetBoolean(Unsafe unsafe, Object obj, long offset) { - return unsafe.getBoolean(obj, offset) && unsafe.getBooleanVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static int unsafeGetByte(Unsafe unsafe, Object obj, long offset) { - return unsafe.getByte(obj, offset) + unsafe.getByteVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static int unsafeGetShort(Unsafe unsafe, Object obj, long offset) { - return unsafe.getShort(obj, offset) + unsafe.getShortVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static int unsafeGetChar(Unsafe unsafe, Object obj, long offset) { - return unsafe.getChar(obj, offset) + unsafe.getCharVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static int unsafeGetInt(Unsafe unsafe, Object obj, long offset) { - return unsafe.getInt(obj, offset) + unsafe.getIntVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static long unsafeGetLong(Unsafe unsafe, Object obj, long offset) { - return unsafe.getLong(obj, offset) + unsafe.getLongVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static float unsafeGetFloat(Unsafe unsafe, Object obj, long offset) { - return unsafe.getFloat(obj, offset) + unsafe.getFloatVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static double unsafeGetDouble(Unsafe unsafe, Object obj, long offset) { - return unsafe.getDouble(obj, offset) + unsafe.getDoubleVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static boolean unsafeGetObject(Unsafe unsafe, Object obj, long offset) { - return unsafe.getObject(obj, offset) == unsafe.getObjectVolatile(obj, offset); - } - - @SuppressWarnings("all") - public static void unsafePutBoolean(Unsafe unsafe, Object obj, long offset, boolean value) { - unsafe.putBoolean(obj, offset, value); - unsafe.putBooleanVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutByte(Unsafe unsafe, Object obj, long offset, byte value) { - unsafe.putByte(obj, offset, value); - unsafe.putByteVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutShort(Unsafe unsafe, Object obj, long offset, short value) { - unsafe.putShort(obj, offset, value); - unsafe.putShortVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutChar(Unsafe unsafe, Object obj, long offset, char value) { - unsafe.putChar(obj, offset, value); - unsafe.putCharVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutInt(Unsafe unsafe, Object obj, long offset, int value) { - unsafe.putInt(obj, offset, value); - unsafe.putIntVolatile(obj, offset, value); - unsafe.putOrderedInt(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutLong(Unsafe unsafe, Object obj, long offset, long value) { - unsafe.putLong(obj, offset, value); - unsafe.putLongVolatile(obj, offset, value); - unsafe.putOrderedLong(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutFloat(Unsafe unsafe, Object obj, long offset, float value) { - unsafe.putFloat(obj, offset, value); - unsafe.putFloatVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutDouble(Unsafe unsafe, Object obj, long offset, double value) { - unsafe.putDouble(obj, offset, value); - unsafe.putDoubleVolatile(obj, offset, value); - } - - @SuppressWarnings("all") - public static void unsafePutObject(Unsafe unsafe, Object obj, long offset, Object value) { - unsafe.putObject(obj, offset, value); - unsafe.putObjectVolatile(obj, offset, value); - unsafe.putOrderedObject(obj, offset, value); - } - - @SuppressWarnings("all") - public static double unsafeDirectMemoryRead(Unsafe unsafe, long address) { - // Unsafe.getBoolean(long) and Unsafe.getObject(long) do not exist - return unsafe.getByte(address) + unsafe.getShort(address) + unsafe.getChar(address) + unsafe.getInt(address) + unsafe.getLong(address) + unsafe.getFloat(address) + unsafe.getDouble(address); - } - - @SuppressWarnings("all") - public static void unsafeDirectMemoryWrite(Unsafe unsafe, long address, byte value) { - // Unsafe.putBoolean(long) and Unsafe.putObject(long) do not exist - unsafe.putByte(address, value); - unsafe.putShort(address, value); - unsafe.putChar(address, (char) value); - unsafe.putInt(address, value); - unsafe.putLong(address, value); - unsafe.putFloat(address, value); - unsafe.putDouble(address, value); - } - - @Test - public void testMathSubstitutions() { - assertInGraph(assertNotInGraph(test("mathAbs"), IfNode.class), MathIntrinsicNode.class); // Java - test("math"); - } - - @SuppressWarnings("all") - public static double mathAbs(double value) { - return Math.abs(value); - } - - @SuppressWarnings("all") - public static double math(double value) { - return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value); - // Math.exp(value) + - // Math.pow(value, 13); - } - - @Test - public void testIntegerSubstitutions() { - assertInGraph(test("integerReverseBytes"), ReverseBytesNode.class); // Java - assertInGraph(test("integerNumberOfLeadingZeros"), BitScanReverseNode.class); // Java - assertInGraph(test("integerNumberOfTrailingZeros"), BitScanForwardNode.class); // Java - assertInGraph(test("integerBitCount"), BitCountNode.class); // Java - } - - @SuppressWarnings("all") - public static int integerReverseBytes(int value) { - return Integer.reverseBytes(value); - } - - @SuppressWarnings("all") - public static int integerNumberOfLeadingZeros(int value) { - return Integer.numberOfLeadingZeros(value); - } - - @SuppressWarnings("all") - public static int integerNumberOfTrailingZeros(int value) { - return Integer.numberOfTrailingZeros(value); - } - - @SuppressWarnings("all") - public static int integerBitCount(int value) { - return Integer.bitCount(value); - } - - @Test - public void testLongSubstitutions() { - assertInGraph(test("longReverseBytes"), ReverseBytesNode.class); // Java - assertInGraph(test("longNumberOfLeadingZeros"), BitScanReverseNode.class); // Java - assertInGraph(test("longNumberOfTrailingZeros"), BitScanForwardNode.class); // Java - assertInGraph(test("longBitCount"), BitCountNode.class); // Java - } - - @SuppressWarnings("all") - public static long longReverseBytes(long value) { - return Long.reverseBytes(value); - } - - @SuppressWarnings("all") - public static long longNumberOfLeadingZeros(long value) { - return Long.numberOfLeadingZeros(value); - } - - @SuppressWarnings("all") - public static long longNumberOfTrailingZeros(long value) { - return Long.numberOfTrailingZeros(value); - } - - @SuppressWarnings("all") - public static int longBitCount(long value) { - return Long.bitCount(value); - } - - @Test - public void testFloatSubstitutions() { - assertInGraph(test("floatToIntBits"), ConvertNode.class); // Java - test("intBitsToFloat"); - } - - @SuppressWarnings("all") - public static int floatToIntBits(float value) { - return Float.floatToIntBits(value); - } - - @SuppressWarnings("all") - public static float intBitsToFloat(int value) { - return Float.intBitsToFloat(value); - } - - @Test - public void testDoubleSubstitutions() { - assertInGraph(test("doubleToLongBits"), ConvertNode.class); // Java - test("longBitsToDouble"); - } - - @SuppressWarnings("all") - public static long doubleToLongBits(double value) { - return Double.doubleToLongBits(value); - } - - @SuppressWarnings("all") - public static double longBitsToDouble(long value) { - return Double.longBitsToDouble(value); - } +public abstract class MethodSubstitutionTest extends GraalCompilerTest { protected StructuredGraph test(final String snippet) { return Debug.scope("MethodSubstitutionTest", runtime.lookupJavaMethod(getMethod(snippet)), new Callable() { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/StandardMethodSubstitutionsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/StandardMethodSubstitutionsTest.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,453 @@ +/* + * Copyright (c) 2012, 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.graal.replacements; + +import static com.oracle.graal.graph.UnsafeAccess.*; +import static com.oracle.graal.replacements.UnsafeSubstitutions.*; + +import java.lang.reflect.*; +import java.util.concurrent.atomic.*; + +import org.junit.*; + +import sun.misc.*; + +import com.oracle.graal.api.replacements.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.replacements.nodes.*; + +/** + * Tests the VM independent {@link MethodSubstitution}s. + */ +public class StandardMethodSubstitutionsTest extends MethodSubstitutionTest { + + static long off(Object o, String name) { + try { + return unsafe.objectFieldOffset(o.getClass().getDeclaredField(name)); + } catch (Exception e) { + Assert.fail(e.toString()); + return 0L; + } + } + + static class Foo { + + boolean z; + byte b; + short s; + char c; + int i; + long l; + float f; + double d; + Object o; + + void testGet(Field field, long offset, String getName, Object value) throws Exception { + field.set(this, value); + Method m1 = Unsafe.class.getDeclaredMethod(getName, Object.class, long.class); + Method m2 = UnsafeSubstitutions.class.getDeclaredMethod(getName, Object.class, Object.class, long.class); + Object expected = m1.invoke(unsafe, this, offset); + Object actual = m2.invoke(null, unsafe, this, offset); + Assert.assertEquals(expected, actual); + } + + void testDirect(Field field, long offset, String type, Object value) throws Exception { + if (type.equals("Boolean") || type.equals("Object")) { + // No direct memory access for these types + return; + } + + long address = unsafe.allocateMemory(offset + 16); + + String getName = "get" + type; + String putName = "put" + type; + Method m1 = Unsafe.class.getDeclaredMethod(putName, long.class, field.getType()); + Method m2 = Unsafe.class.getDeclaredMethod(getName, long.class); + + Method m3 = UnsafeSubstitutions.class.getDeclaredMethod(putName, Object.class, long.class, field.getType()); + Method m4 = UnsafeSubstitutions.class.getDeclaredMethod(getName, Object.class, long.class); + + m1.invoke(unsafe, address + offset, value); + Object expected = m2.invoke(unsafe, address + offset); + + m3.invoke(null, unsafe, address + offset, value); + Object actual = m4.invoke(null, unsafe, address + offset); + + unsafe.freeMemory(address); + Assert.assertEquals(expected, actual); + } + + void testPut(Field field, long offset, String putName, Object value) throws Exception { + Object initialValue = field.get(new Foo()); + field.set(this, initialValue); + + try { + Method m1 = Unsafe.class.getDeclaredMethod(putName, Object.class, long.class, field.getType()); + Method m2 = UnsafeSubstitutions.class.getDeclaredMethod(putName, Object.class, Object.class, long.class, field.getType()); + m1.invoke(unsafe, this, offset, value); + Object expected = field.get(this); + m2.invoke(null, unsafe, this, offset, value); + Object actual = field.get(this); + Assert.assertEquals(expected, actual); + } catch (NoSuchMethodException e) { + if (!putName.startsWith("putOrdered")) { + throw e; + } + } + } + + void test(String fieldName, String typeSuffix, Object value) { + try { + Field field = Foo.class.getDeclaredField(fieldName); + long offset = unsafe.objectFieldOffset(field); + testGet(field, offset, "get" + typeSuffix, value); + testGet(field, offset, "get" + typeSuffix + "Volatile", value); + testPut(field, offset, "put" + typeSuffix, value); + testPut(field, offset, "put" + typeSuffix + "Volatile", value); + testPut(field, offset, "putOrdered" + typeSuffix, value); + testDirect(field, offset, typeSuffix, value); + } catch (Exception e) { + throw new AssertionError(e); + } + } + } + + @Test + public void testUnsafeSubstitutions() throws Exception { + test("unsafeCompareAndSwapInt"); + test("unsafeCompareAndSwapLong"); + test("unsafeCompareAndSwapObject"); + + test("unsafeGetBoolean"); + test("unsafeGetByte"); + test("unsafeGetShort"); + test("unsafeGetChar"); + test("unsafeGetInt"); + test("unsafeGetLong"); + test("unsafeGetFloat"); + test("unsafeGetDouble"); + test("unsafeGetObject"); + + test("unsafePutBoolean"); + test("unsafePutByte"); + test("unsafePutShort"); + test("unsafePutChar"); + test("unsafePutInt"); + test("unsafePutFloat"); + test("unsafePutDouble"); + test("unsafePutObject"); + + test("unsafeDirectMemoryRead"); + test("unsafeDirectMemoryWrite"); + + AtomicInteger a1 = new AtomicInteger(42); + AtomicInteger a2 = new AtomicInteger(42); + assertEquals(unsafe.compareAndSwapInt(a1, off(a1, "value"), 42, 53), compareAndSwapInt(unsafe, a2, off(a2, "value"), 42, 53)); + assertEquals(a1.get(), a2.get()); + + AtomicLong l1 = new AtomicLong(42); + AtomicLong l2 = new AtomicLong(42); + assertEquals(unsafe.compareAndSwapLong(l1, off(l1, "value"), 42, 53), compareAndSwapLong(unsafe, l2, off(l2, "value"), 42, 53)); + assertEquals(l1.get(), l2.get()); + + AtomicReference o1 = new AtomicReference<>("42"); + AtomicReference o2 = new AtomicReference<>("42"); + assertEquals(unsafe.compareAndSwapObject(o1, off(o1, "value"), "42", "53"), compareAndSwapObject(unsafe, o2, off(o2, "value"), "42", "53")); + assertEquals(o1.get(), o2.get()); + + Foo f1 = new Foo(); + f1.test("z", "Boolean", Boolean.TRUE); + f1.test("b", "Byte", Byte.MIN_VALUE); + f1.test("s", "Short", Short.MAX_VALUE); + f1.test("c", "Char", '!'); + f1.test("i", "Int", 1010010); + f1.test("f", "Float", -34.5F); + f1.test("l", "Long", 99999L); + f1.test("d", "Double", 1234.5678D); + f1.test("o", "Object", "object"); + } + + @SuppressWarnings("all") + public static boolean unsafeCompareAndSwapInt(Unsafe unsafe, Object obj, long offset) { + return unsafe.compareAndSwapInt(obj, offset, 0, 1); + } + + @SuppressWarnings("all") + public static boolean unsafeCompareAndSwapLong(Unsafe unsafe, Object obj, long offset) { + return unsafe.compareAndSwapLong(obj, offset, 0, 1); + } + + @SuppressWarnings("all") + public static boolean unsafeCompareAndSwapObject(Unsafe unsafe, Object obj, long offset) { + return unsafe.compareAndSwapObject(obj, offset, null, new Object()); + } + + @SuppressWarnings("all") + public static boolean unsafeGetBoolean(Unsafe unsafe, Object obj, long offset) { + return unsafe.getBoolean(obj, offset) && unsafe.getBooleanVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static int unsafeGetByte(Unsafe unsafe, Object obj, long offset) { + return unsafe.getByte(obj, offset) + unsafe.getByteVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static int unsafeGetShort(Unsafe unsafe, Object obj, long offset) { + return unsafe.getShort(obj, offset) + unsafe.getShortVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static int unsafeGetChar(Unsafe unsafe, Object obj, long offset) { + return unsafe.getChar(obj, offset) + unsafe.getCharVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static int unsafeGetInt(Unsafe unsafe, Object obj, long offset) { + return unsafe.getInt(obj, offset) + unsafe.getIntVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static long unsafeGetLong(Unsafe unsafe, Object obj, long offset) { + return unsafe.getLong(obj, offset) + unsafe.getLongVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static float unsafeGetFloat(Unsafe unsafe, Object obj, long offset) { + return unsafe.getFloat(obj, offset) + unsafe.getFloatVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static double unsafeGetDouble(Unsafe unsafe, Object obj, long offset) { + return unsafe.getDouble(obj, offset) + unsafe.getDoubleVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static boolean unsafeGetObject(Unsafe unsafe, Object obj, long offset) { + return unsafe.getObject(obj, offset) == unsafe.getObjectVolatile(obj, offset); + } + + @SuppressWarnings("all") + public static void unsafePutBoolean(Unsafe unsafe, Object obj, long offset, boolean value) { + unsafe.putBoolean(obj, offset, value); + unsafe.putBooleanVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutByte(Unsafe unsafe, Object obj, long offset, byte value) { + unsafe.putByte(obj, offset, value); + unsafe.putByteVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutShort(Unsafe unsafe, Object obj, long offset, short value) { + unsafe.putShort(obj, offset, value); + unsafe.putShortVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutChar(Unsafe unsafe, Object obj, long offset, char value) { + unsafe.putChar(obj, offset, value); + unsafe.putCharVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutInt(Unsafe unsafe, Object obj, long offset, int value) { + unsafe.putInt(obj, offset, value); + unsafe.putIntVolatile(obj, offset, value); + unsafe.putOrderedInt(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutLong(Unsafe unsafe, Object obj, long offset, long value) { + unsafe.putLong(obj, offset, value); + unsafe.putLongVolatile(obj, offset, value); + unsafe.putOrderedLong(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutFloat(Unsafe unsafe, Object obj, long offset, float value) { + unsafe.putFloat(obj, offset, value); + unsafe.putFloatVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutDouble(Unsafe unsafe, Object obj, long offset, double value) { + unsafe.putDouble(obj, offset, value); + unsafe.putDoubleVolatile(obj, offset, value); + } + + @SuppressWarnings("all") + public static void unsafePutObject(Unsafe unsafe, Object obj, long offset, Object value) { + unsafe.putObject(obj, offset, value); + unsafe.putObjectVolatile(obj, offset, value); + unsafe.putOrderedObject(obj, offset, value); + } + + @SuppressWarnings("all") + public static double unsafeDirectMemoryRead(Unsafe unsafe, long address) { + // Unsafe.getBoolean(long) and Unsafe.getObject(long) do not exist + return unsafe.getByte(address) + unsafe.getShort(address) + unsafe.getChar(address) + unsafe.getInt(address) + unsafe.getLong(address) + unsafe.getFloat(address) + unsafe.getDouble(address); + } + + @SuppressWarnings("all") + public static void unsafeDirectMemoryWrite(Unsafe unsafe, long address, byte value) { + // Unsafe.putBoolean(long) and Unsafe.putObject(long) do not exist + unsafe.putByte(address, value); + unsafe.putShort(address, value); + unsafe.putChar(address, (char) value); + unsafe.putInt(address, value); + unsafe.putLong(address, value); + unsafe.putFloat(address, value); + unsafe.putDouble(address, value); + } + + @Test + public void testMathSubstitutions() { + assertInGraph(assertNotInGraph(test("mathAbs"), IfNode.class), MathIntrinsicNode.class); // Java + test("math"); + + double value = 34567.891D; + assertEquals(Math.sqrt(value), MathSubstitutionsX86.sqrt(value)); + assertEquals(Math.log(value), MathSubstitutionsX86.log(value)); + assertEquals(Math.log10(value), MathSubstitutionsX86.log10(value)); + assertEquals(Math.sin(value), MathSubstitutionsX86.sin(value)); + assertEquals(Math.cos(value), MathSubstitutionsX86.cos(value)); + assertEquals(Math.tan(value), MathSubstitutionsX86.tan(value)); + } + + @SuppressWarnings("all") + public static double mathAbs(double value) { + return Math.abs(value); + } + + @SuppressWarnings("all") + public static double math(double value) { + return Math.sqrt(value) + Math.log(value) + Math.log10(value) + Math.sin(value) + Math.cos(value) + Math.tan(value); + // Math.exp(value) + + // Math.pow(value, 13); + } + + @Test + public void testIntegerSubstitutions() { + assertInGraph(test("integerReverseBytes"), ReverseBytesNode.class); // Java + assertInGraph(test("integerNumberOfLeadingZeros"), BitScanReverseNode.class); // Java + assertInGraph(test("integerNumberOfTrailingZeros"), BitScanForwardNode.class); // Java + assertInGraph(test("integerBitCount"), BitCountNode.class); // Java + + for (int i : new int[]{Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE}) { + assertEquals(Integer.reverseBytes(i), IntegerSubstitutions.reverseBytes(i)); + assertEquals(Integer.numberOfLeadingZeros(i), IntegerSubstitutions.numberOfLeadingZeros(i)); + assertEquals(Integer.numberOfTrailingZeros(i), IntegerSubstitutions.numberOfTrailingZeros(i)); + assertEquals(Integer.bitCount(i), IntegerSubstitutions.bitCount(i)); + } + } + + @SuppressWarnings("all") + public static int integerReverseBytes(int value) { + return Integer.reverseBytes(value); + } + + @SuppressWarnings("all") + public static int integerNumberOfLeadingZeros(int value) { + return Integer.numberOfLeadingZeros(value); + } + + @SuppressWarnings("all") + public static int integerNumberOfTrailingZeros(int value) { + return Integer.numberOfTrailingZeros(value); + } + + @SuppressWarnings("all") + public static int integerBitCount(int value) { + return Integer.bitCount(value); + } + + @Test + public void testLongSubstitutions() { + assertInGraph(test("longReverseBytes"), ReverseBytesNode.class); // Java + assertInGraph(test("longNumberOfLeadingZeros"), BitScanReverseNode.class); // Java + assertInGraph(test("longNumberOfTrailingZeros"), BitScanForwardNode.class); // Java + assertInGraph(test("longBitCount"), BitCountNode.class); // Java + + for (long l : new long[]{Long.MIN_VALUE, -1L, 0L, 1L, Long.MAX_VALUE}) { + assertEquals(Long.reverseBytes(l), LongSubstitutions.reverseBytes(l)); + assertEquals(Long.numberOfLeadingZeros(l), LongSubstitutions.numberOfLeadingZeros(l)); + assertEquals(Long.numberOfTrailingZeros(l), LongSubstitutions.numberOfTrailingZeros(l)); + assertEquals(Long.bitCount(l), LongSubstitutions.bitCount(l)); + } + } + + @SuppressWarnings("all") + public static long longReverseBytes(long value) { + return Long.reverseBytes(value); + } + + @SuppressWarnings("all") + public static long longNumberOfLeadingZeros(long value) { + return Long.numberOfLeadingZeros(value); + } + + @SuppressWarnings("all") + public static long longNumberOfTrailingZeros(long value) { + return Long.numberOfTrailingZeros(value); + } + + @SuppressWarnings("all") + public static int longBitCount(long value) { + return Long.bitCount(value); + } + + @Test + public void testFloatSubstitutions() { + assertInGraph(test("floatToIntBits"), ConvertNode.class); // Java + test("intBitsToFloat"); + } + + @SuppressWarnings("all") + public static int floatToIntBits(float value) { + return Float.floatToIntBits(value); + } + + @SuppressWarnings("all") + public static float intBitsToFloat(int value) { + return Float.intBitsToFloat(value); + } + + @Test + public void testDoubleSubstitutions() { + assertInGraph(test("doubleToLongBits"), ConvertNode.class); // Java + test("longBitsToDouble"); + } + + @SuppressWarnings("all") + public static long doubleToLongBits(double value) { + return Double.doubleToLongBits(value); + } + + @SuppressWarnings("all") + public static double longBitsToDouble(long value) { + return Double.longBitsToDouble(value); + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/META-INF/services/com.oracle.graal.replacements.ReplacementsProvider --- a/graal/com.oracle.graal.replacements/src/META-INF/services/com.oracle.graal.replacements.ReplacementsProvider Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -com.oracle.graal.replacements.GraalMethodSubstitutions diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/AliasResolutionPhase.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/AliasResolutionPhase.java Thu Mar 28 12:55:13 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -/* - * Copyright (c) 2011, 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.graal.replacements; - -import static com.oracle.graal.api.meta.MetaUtil.*; -import static com.oracle.graal.replacements.ReplacementsInstaller.*; -import static java.lang.Thread.*; -import static java.lang.reflect.Modifier.*; - -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.replacements.*; -import com.oracle.graal.graph.*; -import com.oracle.graal.nodes.*; -import com.oracle.graal.nodes.java.*; -import com.oracle.graal.phases.*; - -/** - * Resolves field and method {@linkplain Alias aliases} to the aliased fields and methods. - */ -public class AliasResolutionPhase extends Phase { - - private final MetaAccessProvider runtime; - - public AliasResolutionPhase(MetaAccessProvider runtime) { - this.runtime = runtime; - } - - @Override - protected void run(StructuredGraph graph) { - for (LoadFieldNode loadField : graph.getNodes(LoadFieldNode.class)) { - ResolvedJavaField field = loadField.field(); - Field aliasedField = getAliasedField(field); - if (aliasedField != null) { - LoadFieldNode replacement = graph.add(new LoadFieldNode(loadField.object(), runtime.lookupJavaField(aliasedField))); - graph.replaceFixedWithFixed(loadField, replacement); - } - } - for (StoreFieldNode storeField : graph.getNodes().filter(StoreFieldNode.class)) { - ResolvedJavaField field = storeField.field(); - Field aliasedField = getAliasedField(field); - if (aliasedField != null) { - StoreFieldNode replacement = graph.add(new StoreFieldNode(storeField.object(), runtime.lookupJavaField(aliasedField), storeField.value())); - graph.replaceFixedWithFixed(storeField, replacement); - } - } - - for (Invoke invoke : graph.getInvokes()) { - if (invoke.callTarget() instanceof MethodCallTargetNode) { - MethodCallTargetNode methodCallTarget = invoke.methodCallTarget(); - ResolvedJavaMethod method = methodCallTarget.targetMethod(); - Method aliasedMethod = getAliasedMethod(method); - if (aliasedMethod != null) { - methodCallTarget.setTargetMethod(runtime.lookupJavaMethod(aliasedMethod)); - } - } - } - } - - private static Field getAliasedField(ResolvedJavaField field) { - Alias alias = field.getAnnotation(Alias.class); - if (alias == null) { - return null; - } - Class holder = declaringClass(alias, field); - if (holder == null) { - assert alias.optional(); - return null; - } - - String name = alias.name(); - if (name.isEmpty()) { - name = field.getName(); - } - - Class type; - if (alias.descriptor().isEmpty()) { - type = getMirrorOrFail((ResolvedJavaType) field.getType(), currentThread().getContextClassLoader()); - } else { - type = resolveType(alias.descriptor(), false); - } - - for (Field f : holder.getDeclaredFields()) { - if (f.getName().equals(name) && f.getType().equals(type) && isStatic(f.getModifiers()) == isStatic(field.getModifiers())) { - return f; - } - } - if (alias.optional()) { - return null; - } - throw new GraalInternalError("Could not resolve field alias %s", format("%T %H.%n", field)); - } - - private Method getAliasedMethod(ResolvedJavaMethod method) { - Alias alias = method.getAnnotation(Alias.class); - if (alias == null) { - return null; - } - Class holder = declaringClass(alias, method); - if (holder == null) { - assert alias.optional(); - return null; - } - - String name = alias.name(); - if (name.isEmpty()) { - name = method.getName(); - } - - Class[] parameters; - if (alias.descriptor().isEmpty()) { - parameters = NodeIntrinsificationPhase.signatureToTypes(method.getSignature(), null); - } else { - Signature signature = runtime.parseMethodDescriptor(alias.descriptor()); - parameters = NodeIntrinsificationPhase.signatureToTypes(signature, null); - } - - for (Method m : holder.getDeclaredMethods()) { - if (m.getName().equals(name) && Arrays.equals(m.getParameterTypes(), parameters) && isStatic(m.getModifiers()) == isStatic(method.getModifiers())) { - return m; - } - } - if (alias.optional()) { - return null; - } - throw new GraalInternalError("Could not resolve method alias %s", format("%R %H.%n(%P)", method)); - } - - private static Class getInnerClass(Class outerClass, String innerClassSimpleName) { - for (Class innerClass : outerClass.getDeclaredClasses()) { - if (innerClass.getSimpleName().equals(innerClassSimpleName)) { - return innerClass; - } - } - return null; - } - - private static Class declaringClass(Alias alias, Object member) { - Class holder; - if (alias.declaringClass() == Alias.class) { - assert !alias.declaringClassName().isEmpty() : "declaring class missing for alias " + member; - holder = resolveType(alias.declaringClassName(), alias.optional()); - } else { - assert alias.declaringClassName().isEmpty() : "declaring class specified more than once for alias " + member; - holder = alias.declaringClass(); - } - if (holder != null && !alias.innerClass().isEmpty()) { - holder = getInnerClass(holder, alias.innerClass()); - } - return holder; - } -} diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/GraalMethodSubstitutions.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,11 +22,13 @@ */ package com.oracle.graal.replacements; +import com.oracle.graal.api.runtime.*; import com.oracle.graal.phases.*; /** * Method substitutions that are VM-independent. */ +@ServiceProvider(ReplacementsProvider.class) public class GraalMethodSubstitutions implements ReplacementsProvider { public void installReplacements(ReplacementsInstaller installer) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/MathSubstitutionsX86.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/MathSubstitutionsX86.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/MathSubstitutionsX86.java Thu Mar 28 12:58:50 2013 +0100 @@ -28,7 +28,7 @@ import com.oracle.graal.graph.Node.NodeIntrinsic; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.replacements.nodes.*; -import com.oracle.graal.replacements.nodes.MathIntrinsicNode.*; +import com.oracle.graal.replacements.nodes.MathIntrinsicNode.Operation; /** * Substitutions for {@link java.lang.Math} methods. @@ -96,5 +96,14 @@ public static final Descriptor ARITHMETIC_TAN = new Descriptor("arithmeticTan", false, double.class, double.class); @NodeIntrinsic(value = RuntimeCallNode.class, setStampFromReturnType = true) - public static native double callDouble(@ConstantNodeParameter Descriptor descriptor, double value); + public static double callDouble(@ConstantNodeParameter Descriptor descriptor, double value) { + if (descriptor == ARITHMETIC_SIN) { + return Math.sin(value); + } + if (descriptor == ARITHMETIC_COS) { + return Math.cos(value); + } + assert descriptor == ARITHMETIC_TAN; + return Math.tan(value); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java Thu Mar 28 12:58:50 2013 +0100 @@ -89,7 +89,7 @@ // Create the new node instance. Class c = getNodeClass(target, intrinsic); - Node newInstance = createNodeInstance(c, parameterTypes, returnType, intrinsic.setStampFromReturnType(), nodeConstructorArguments); + Node newInstance = createNodeInstance(runtime, c, parameterTypes, returnType, intrinsic.setStampFromReturnType(), nodeConstructorArguments); // Replace the invoke with the new node. invoke.node().graph().add(newInstance); @@ -260,11 +260,19 @@ static final int VARARGS = 0x00000080; - private static Node createNodeInstance(Class nodeClass, Class[] parameterTypes, ResolvedJavaType returnType, boolean setStampFromReturnType, Object[] nodeConstructorArguments) { + private static Node createNodeInstance(MetaAccessProvider runtime, Class nodeClass, Class[] parameterTypes, ResolvedJavaType returnType, boolean setStampFromReturnType, + Object[] nodeConstructorArguments) { Object[] arguments = null; Constructor constructor = null; + boolean needsMetaAccessProviderArgument = false; nextConstructor: for (Constructor c : nodeClass.getDeclaredConstructors()) { + needsMetaAccessProviderArgument = false; Class[] signature = c.getParameterTypes(); + if (signature.length != 0 && signature[0] == MetaAccessProvider.class) { + // Chop off the MetaAccessProvider first parameter + signature = Arrays.copyOfRange(signature, 1, signature.length); + needsMetaAccessProviderArgument = true; + } if ((c.getModifiers() & VARARGS) != 0) { int fixedArgs = signature.length - 1; if (parameterTypes.length < fixedArgs) { @@ -285,7 +293,6 @@ continue nextConstructor; } } - arguments = Arrays.copyOf(nodeConstructorArguments, fixedArgs + 1); int varargsLength = nodeConstructorArguments.length - fixedArgs; Object varargs = Array.newInstance(componentType, varargsLength); @@ -304,6 +311,12 @@ if (constructor == null) { throw new GraalInternalError("Could not find constructor in " + nodeClass + " compatible with signature " + Arrays.toString(parameterTypes)); } + if (needsMetaAccessProviderArgument) { + Object[] copy = new Object[arguments.length + 1]; + System.arraycopy(arguments, 0, copy, 1, arguments.length); + copy[0] = runtime; + arguments = copy; + } constructor.setAccessible(true); try { ValueNode intrinsicNode = (ValueNode) constructor.newInstance(arguments); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsInstaller.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsInstaller.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/ReplacementsInstaller.java Thu Mar 28 12:58:50 2013 +0100 @@ -210,13 +210,16 @@ * Does final processing of a snippet graph. */ protected void finalizeGraph(ResolvedJavaMethod method, StructuredGraph graph) { - new AliasResolutionPhase(runtime).apply(graph); new NodeIntrinsificationPhase(runtime, pool).apply(graph); assert SnippetTemplate.hasConstantParameter(method) || NodeIntrinsificationVerificationPhase.verify(graph); - new SnippetFrameStateCleanupPhase().apply(graph); - new DeadCodeEliminationPhase().apply(graph); - new InsertStateAfterPlaceholderPhase().apply(graph); + if (substitute == null) { + new SnippetFrameStateCleanupPhase().apply(graph); + new DeadCodeEliminationPhase().apply(graph); + new InsertStateAfterPlaceholderPhase().apply(graph); + } else { + new DeadCodeEliminationPhase().apply(graph); + } } public StructuredGraph makeGraph(final ResolvedJavaMethod method, final SnippetInliningPolicy policy) { @@ -256,7 +259,6 @@ Debug.dump(graph, "%s: %s", method.getName(), GraphBuilderPhase.class.getSimpleName()); new WordTypeVerificationPhase(runtime, target.wordKind).apply(graph); - new AliasResolutionPhase(runtime).apply(graph); new NodeIntrinsificationPhase(runtime, pool).apply(graph); return graph; @@ -279,7 +281,6 @@ * Called after all inlining for a given graph is complete. */ protected void afterInlining(StructuredGraph graph) { - new AliasResolutionPhase(runtime).apply(graph); new NodeIntrinsificationPhase(runtime, pool).apply(graph); new WordTypeRewriterPhase(runtime, target.wordKind).apply(graph); diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitCountNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitCountNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitCountNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -54,10 +54,14 @@ } @NodeIntrinsic - public static native int bitCount(int v); + public static int bitCount(int v) { + return Integer.bitCount(v); + } @NodeIntrinsic - public static native int bitCount(long v); + public static int bitCount(long v) { + return Long.bitCount(v); + } @Override public void generate(LIRGenerator gen) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanForwardNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanForwardNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanForwardNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -54,7 +54,16 @@ } @NodeIntrinsic - public static native int scan(long v); + public static int scan(long v) { + if (v == 0) { + return -1; + } + int index = 0; + while (((1L << index) & v) == 0) { + ++index; + } + return index; + } @Override public void generate(LIRGenerator gen) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanReverseNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanReverseNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BitScanReverseNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -54,10 +54,28 @@ } @NodeIntrinsic - public static native int scan(int v); + public static int scan(int v) { + if (v == 0) { + return -1; + } + int index = 31; + while (((1 << index) & v) == 0) { + --index; + } + return index; + } @NodeIntrinsic - public static native int scan(long v); + public static int scan(long v) { + if (v == 0) { + return -1; + } + int index = 63; + while (((1L << index) & v) == 0) { + --index; + } + return index; + } @Override public void generate(LIRGenerator gen) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BranchProbabilityNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BranchProbabilityNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/BranchProbabilityNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -75,7 +75,9 @@ GraphUtil.killCFG(this); } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void probability(@ConstantNodeParameter double probability); + public static void probability(@ConstantNodeParameter double probability) { + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectReadNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectReadNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectReadNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.replacements.nodes; +import static com.oracle.graal.graph.UnsafeAccess.*; + import com.oracle.graal.api.meta.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; @@ -48,6 +50,31 @@ gen.setResult(this, gen.emitLoad(readKind, gen.operand(address), 0, Value.ILLEGAL, 0, false)); } + @SuppressWarnings("unchecked") @NodeIntrinsic - public static native T read(long address, @ConstantNodeParameter Kind kind); + public static T read(long address, @ConstantNodeParameter Kind kind) { + if (kind == Kind.Boolean) { + return (T) Boolean.valueOf(unsafe.getByte(address) != 0); + } + if (kind == Kind.Byte) { + return (T) (Byte) unsafe.getByte(address); + } + if (kind == Kind.Short) { + return (T) (Short) unsafe.getShort(address); + } + if (kind == Kind.Char) { + return (T) (Character) unsafe.getChar(address); + } + if (kind == Kind.Int) { + return (T) (Integer) unsafe.getInt(address); + } + if (kind == Kind.Float) { + return (T) (Float) unsafe.getFloat(address); + } + if (kind == Kind.Long) { + return (T) (Long) unsafe.getLong(address); + } + assert kind == Kind.Double; + return (T) (Double) unsafe.getDouble(address); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectStoreNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectStoreNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/DirectStoreNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -22,6 +22,8 @@ */ package com.oracle.graal.replacements.nodes; +import static com.oracle.graal.graph.UnsafeAccess.*; + import com.oracle.graal.api.meta.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.extended.*; @@ -57,27 +59,52 @@ * are used). */ + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, boolean value, @ConstantNodeParameter Kind kind); - - @NodeIntrinsic - public static native void store(long address, byte value, @ConstantNodeParameter Kind kind); + public static void store(long address, boolean value, @ConstantNodeParameter Kind kind) { + int b = value ? 1 : 0; + unsafe.putByte(address, (byte) b); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, short value, @ConstantNodeParameter Kind kind); + public static void store(long address, byte value, @ConstantNodeParameter Kind kind) { + unsafe.putByte(address, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, char value, @ConstantNodeParameter Kind kind); + public static void store(long address, short value, @ConstantNodeParameter Kind kind) { + unsafe.putShort(address, value); + } + + @SuppressWarnings("unused") + @NodeIntrinsic + public static void store(long address, char value, @ConstantNodeParameter Kind kind) { + unsafe.putChar(address, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, int value, @ConstantNodeParameter Kind kind); + public static void store(long address, int value, @ConstantNodeParameter Kind kind) { + unsafe.putInt(address, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, long value, @ConstantNodeParameter Kind kind); + public static void store(long address, long value, @ConstantNodeParameter Kind kind) { + unsafe.putLong(address, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, float value, @ConstantNodeParameter Kind kind); + public static void store(long address, float value, @ConstantNodeParameter Kind kind) { + unsafe.putFloat(address, value); + } + @SuppressWarnings("unused") @NodeIntrinsic - public static native void store(long address, double value, @ConstantNodeParameter Kind kind); + public static void store(long address, double value, @ConstantNodeParameter Kind kind) { + unsafe.putDouble(address, value); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MathIntrinsicNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MathIntrinsicNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/MathIntrinsicNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -113,5 +113,23 @@ } @NodeIntrinsic - public static native double compute(double x, @ConstantNodeParameter Operation op); + public static double compute(double value, @ConstantNodeParameter Operation op) { + switch (op) { + case ABS: + return Math.abs(value); + case SQRT: + return Math.sqrt(value); + case LOG: + return Math.log(value); + case LOG10: + return Math.log10(value); + case SIN: + return Math.sin(value); + case COS: + return Math.cos(value); + case TAN: + return Math.tan(value); + } + throw new GraalInternalError("unknown op %s", op); + } } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/nodes/ReverseBytesNode.java Thu Mar 28 12:58:50 2013 +0100 @@ -55,10 +55,14 @@ } @NodeIntrinsic - public static native int reverse(int v); + public static int reverse(int v) { + return Integer.reverseBytes(v); + } @NodeIntrinsic - public static native long reverse(long v); + public static long reverse(long v) { + return Long.reverseBytes(v); + } @Override public void generate(LIRGenerator gen) { diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.service.processor/src/META-INF/services/javax.annotation.processing.Processor --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.service.processor/src/META-INF/services/javax.annotation.processing.Processor Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,1 @@ +com.oracle.graal.service.processor.ServiceProviderProcessor diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.service.processor/src/com/oracle/graal/service/processor/ServiceProviderProcessor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.service.processor/src/com/oracle/graal/service/processor/ServiceProviderProcessor.java Thu Mar 28 12:58:50 2013 +0100 @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2013, 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.graal.service.processor; + +import java.io.*; +import java.util.*; + +import javax.annotation.processing.*; +import javax.lang.model.*; +import javax.lang.model.element.*; +import javax.lang.model.type.*; +import javax.tools.Diagnostic.Kind; +import javax.tools.*; + +import com.oracle.graal.api.runtime.*; + +@SupportedSourceVersion(SourceVersion.RELEASE_7) +@SupportedAnnotationTypes("com.oracle.graal.api.runtime.ServiceProvider") +public class ServiceProviderProcessor extends AbstractProcessor { + + private Map> serviceMap; + + public ServiceProviderProcessor() { + serviceMap = new HashMap<>(); + } + + private void addProvider(String serviceName, TypeElement serviceProvider) { + Set providers = serviceMap.get(serviceName); + if (providers == null) { + providers = new HashSet<>(); + serviceMap.put(serviceName, providers); + } + providers.add(serviceProvider); + } + + private void generateServicesFiles() { + Filer filer = processingEnv.getFiler(); + for (Map.Entry> entry : serviceMap.entrySet()) { + String filename = "META-INF/services/" + entry.getKey(); + TypeElement[] providers = entry.getValue().toArray(new TypeElement[0]); + try { + FileObject servicesFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", filename, providers); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(servicesFile.openOutputStream(), "UTF-8")); + for (TypeElement provider : providers) { + writer.println(provider.getQualifiedName()); + } + writer.close(); + } catch (IOException e) { + processingEnv.getMessager().printMessage(Kind.ERROR, e.getMessage()); + } + } + } + + private boolean verifyAnnotation(TypeMirror serviceInterface, TypeElement serviceProvider) { + if (!processingEnv.getTypeUtils().isSubtype(serviceProvider.asType(), serviceInterface)) { + String msg = String.format("Service provider class %s doesn't implement service interface %s", serviceProvider.getSimpleName(), serviceInterface); + processingEnv.getMessager().printMessage(Kind.ERROR, msg, serviceProvider); + return false; + } + + return true; + } + + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + if (roundEnv.processingOver()) { + generateServicesFiles(); + return true; + } + + for (Element element : roundEnv.getElementsAnnotatedWith(ServiceProvider.class)) { + assert element.getKind().isClass(); + ServiceProvider annotation = element.getAnnotation(ServiceProvider.class); + try { + annotation.value(); + } catch (MirroredTypeException ex) { + TypeMirror serviceInterface = ex.getTypeMirror(); + TypeElement serviceProvider = (TypeElement) element; + if (verifyAnnotation(serviceInterface, serviceProvider)) { + String interfaceName = ex.getTypeMirror().toString(); + addProvider(interfaceName, serviceProvider); + } + } + } + return true; + } +} diff -r 02ef91b94656 -r cd9e8dd9f488 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 Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Thu Mar 28 12:58:50 2013 +0100 @@ -63,13 +63,14 @@ FROM_UNSIGNED, FROM_SIGNED, FROM_OBJECT, + FROM_ARRAY, TO_OBJECT, TO_RAW_VALUE, } // @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(); @@ -146,6 +147,9 @@ @Operation(opcode = Opcode.FROM_OBJECT) public static native Pointer fromObject(Object val); + @Operation(opcode = Opcode.FROM_ARRAY) + public static native Pointer fromArray(Object oop, Object location); + @Override @Operation(opcode = Opcode.TO_OBJECT) public native Object toObject(); @@ -645,7 +649,9 @@ @Override @Operation(opcode = Opcode.READ) - public native Object readObject(WordBase offset, Object locationIdentity); + public Object readObject(WordBase offset, Object locationIdentity) { + return unsafe.getObject(null, add((Word) offset).unbox()); + } @Override @Operation(opcode = Opcode.READ) @@ -1054,7 +1060,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]; } diff -r 02ef91b94656 -r cd9e8dd9f488 graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Thu Mar 28 12:55:13 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Thu Mar 28 12:58:50 2013 +0100 @@ -176,6 +176,11 @@ replace(invoke, graph.unique(new UnsafeCastNode(arguments.get(0), StampFactory.forKind(wordKind)))); break; + case FROM_ARRAY: + assert arguments.size() == 2; + replace(invoke, graph.unique(new ComputeAddressNode(arguments.get(0), arguments.get(1), StampFactory.forKind(wordKind)))); + break; + case TO_OBJECT: assert arguments.size() == 1; replace(invoke, graph.unique(new UnsafeCastNode(arguments.get(0), invoke.node().stamp()))); diff -r 02ef91b94656 -r cd9e8dd9f488 make/build-graal.xml --- a/make/build-graal.xml Thu Mar 28 12:55:13 2013 +0100 +++ b/make/build-graal.xml Thu Mar 28 12:58:50 2013 +0100 @@ -49,8 +49,8 @@ + - diff -r 02ef91b94656 -r cd9e8dd9f488 mx/commands.py --- a/mx/commands.py Thu Mar 28 12:55:13 2013 +0100 +++ b/mx/commands.py Thu Mar 28 12:58:50 2013 +0100 @@ -1127,6 +1127,15 @@ vm = _vm; sanitycheck.getSPECjbb2013(benchArgs).bench(vm, opts=vmArgs) +def specjbb2005(args): + """runs the composite SPECjbb2005 benchmark + + All options begining with - will be passed to the vm""" + benchArgs = [a for a in args if a[0] != '-'] + vmArgs = [a for a in args if a[0] == '-'] + vm = _vm; + sanitycheck.getSPECjbb2005(benchArgs).bench(vm, opts=vmArgs) + def hsdis(args, copyToDir=None): """download the hsdis library @@ -1232,6 +1241,7 @@ 'scaladacapo': [scaladacapo, '[[n] benchmark] [VM options|@Scala DaCapo options]'], 'specjvm2008': [specjvm2008, '[VM options|specjvm2008 options (-v, -ikv, -ict, -wt, -it)]'], 'specjbb2013': [specjbb2013, '[VM options]'], + 'specjbb2005': [specjbb2005, '[VM options]'], #'example': [example, '[-v] example names...'], 'gate' : [gate, '[-options]'], 'gv' : [gv, ''], diff -r 02ef91b94656 -r cd9e8dd9f488 mx/projects --- a/mx/projects Thu Mar 28 12:55:13 2013 +0100 +++ b/mx/projects Thu Mar 28 12:58:50 2013 +0100 @@ -65,6 +65,13 @@ project@com.oracle.graal.api.replacements@checkstyle=com.oracle.graal.graph project@com.oracle.graal.api.replacements@javaCompliance=1.7 +# graal.service.processor +project@com.oracle.graal.service.processor@subDir=graal +project@com.oracle.graal.service.processor@sourceDirs=src +project@com.oracle.graal.service.processor@dependencies=com.oracle.graal.api.runtime +project@com.oracle.graal.service.processor@checkstyle=com.oracle.graal.graph +project@com.oracle.graal.service.processor@javaCompliance=1.7 + # graal.amd64 project@com.oracle.graal.amd64@subDir=graal project@com.oracle.graal.amd64@sourceDirs=src @@ -89,7 +96,7 @@ # graal.hotspot project@com.oracle.graal.hotspot@subDir=graal project@com.oracle.graal.hotspot@sourceDirs=src -project@com.oracle.graal.hotspot@dependencies=com.oracle.graal.replacements,com.oracle.graal.api.runtime,com.oracle.graal.printer +project@com.oracle.graal.hotspot@dependencies=com.oracle.graal.replacements,com.oracle.graal.printer project@com.oracle.graal.hotspot@checkstyle=com.oracle.graal.graph project@com.oracle.graal.hotspot@annotationProcessors=com.oracle.graal.replacements.verifier project@com.oracle.graal.hotspot@javaCompliance=1.7 @@ -193,10 +200,10 @@ # graal.replacements project@com.oracle.graal.replacements@subDir=graal project@com.oracle.graal.replacements@sourceDirs=src -project@com.oracle.graal.replacements@dependencies=com.oracle.graal.compiler,com.oracle.graal.java,com.oracle.graal.word +project@com.oracle.graal.replacements@dependencies=com.oracle.graal.compiler,com.oracle.graal.java,com.oracle.graal.word,com.oracle.graal.api.runtime project@com.oracle.graal.replacements@checkstyle=com.oracle.graal.graph project@com.oracle.graal.replacements@javaCompliance=1.7 -project@com.oracle.graal.replacements@annotationProcessors=com.oracle.graal.replacements.verifier +project@com.oracle.graal.replacements@annotationProcessors=com.oracle.graal.replacements.verifier,com.oracle.graal.service.processor # graal.replacements.amd64 project@com.oracle.graal.replacements.amd64@subDir=graal diff -r 02ef91b94656 -r cd9e8dd9f488 mx/sanitycheck.py --- a/mx/sanitycheck.py Thu Mar 28 12:55:13 2013 +0100 +++ b/mx/sanitycheck.py Thu Mar 28 12:58:50 2013 +0100 @@ -27,6 +27,8 @@ import re, mx, commands, os, sys, StringIO, subprocess from os.path import isfile, join, exists +gc='UseSerialGC' + dacapoSanityWarmup = { 'avrora': [0, 0, 3, 6, 13], 'batik': [0, 0, 5, 5, 20], @@ -107,7 +109,7 @@ success = re.compile(r"^Valid run, Score is [0-9]+$", re.MULTILINE) matcher = ValuesMatcher(score, {'group' : 'SPECjbb2005', 'name' : 'score', 'score' : ''}) classpath = ['jbb.jar', 'check.jar'] - return Test("SPECjbb2005", ['spec.jbb.JBBmain', '-propfile', 'SPECjbb.props'] + benchArgs, [success], [error], [matcher], vmOpts=['-Xms3g', '-XX:+UseSerialGC', '-XX:-UseCompressedOops', '-cp', os.pathsep.join(classpath)], defaultCwd=specjbb2005) + return Test("SPECjbb2005", ['spec.jbb.JBBmain', '-propfile', 'SPECjbb.props'] + benchArgs, [success], [error], [matcher], vmOpts=['-Xms3g', '-XX:+'+gc, '-XX:-UseCompressedOops', '-cp', os.pathsep.join(classpath)], defaultCwd=specjbb2005) def getSPECjbb2013(benchArgs = []): @@ -144,7 +146,7 @@ if skipCheck: opts += ['-ict'] - return Test("SPECjvm2008", ['-jar', 'SPECjvm2008.jar'] + opts + benchArgs, [success], [error], [matcher], vmOpts=['-Xms3g', '-XX:+UseSerialGC', '-XX:-UseCompressedOops'], defaultCwd=specjvm2008) + return Test("SPECjvm2008", ['-jar', 'SPECjvm2008.jar'] + opts + benchArgs, [success], [error], [matcher], vmOpts=['-Xms3g', '-XX:+'+gc, '-XX:-UseCompressedOops'], defaultCwd=specjvm2008) def getDacapos(level=SanityCheckLevel.Normal, gateBuildLevel=None, dacapoArgs=[]): checks = [] @@ -176,7 +178,7 @@ dacapoMatcher = ValuesMatcher(dacapoTime, {'group' : 'DaCapo', 'name' : '', 'score' : '