# HG changeset patch # User Lukas Stadler # Date 1360005837 -3600 # Node ID 14720c279875989568d18bfe6360998fc6fa637f # Parent ec6dc1326b15942baed49f549139a4d41582b918# Parent 61fbe80af62e90457566b1298aa25ef714b963da Merge diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java --- a/graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.amd64/src/com/oracle/graal/amd64/AMD64.java Mon Feb 04 20:23:57 2013 +0100 @@ -26,6 +26,8 @@ import static com.oracle.graal.api.code.Register.RegisterFlag.*; import static com.oracle.graal.api.meta.Kind.*; +import java.nio.*; + import com.oracle.graal.api.code.*; import com.oracle.graal.api.code.Register.*; @@ -109,7 +111,7 @@ public AMD64() { super("AMD64", 8, - ByteOrder.LittleEndian, + ByteOrder.LITTLE_ENDIAN, allRegisters, LOAD_STORE | STORE_STORE, 1, diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/Architecture.java Mon Feb 04 20:23:57 2013 +0100 @@ -22,9 +22,10 @@ */ package com.oracle.graal.api.code; +import java.nio.*; import java.util.*; -import com.oracle.graal.api.code.Register.*; +import com.oracle.graal.api.code.Register.RegisterFlag; /** * Represents a CPU architecture, including information such as its endianness, CPU registers, word @@ -33,13 +34,6 @@ public abstract class Architecture { /** - * The endianness of the architecture. - */ - public static enum ByteOrder { - LittleEndian, BigEndian - } - - /** * The number of bits required in a bit map covering all the registers that may store * references. The bit position of a register in the map is the register's * {@linkplain Register#number number}. diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.interpreter/overview.html --- a/graal/com.oracle.graal.api.interpreter/overview.html Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - - - - - - - - -Documentation for the com.oracle.graal.api.interpreter project. - - - diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/Interpreter.java --- a/graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/Interpreter.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +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.api.interpreter; - -import com.oracle.graal.api.meta.*; - -public interface Interpreter extends VirtualMachineComponent { - - boolean initialize(String args); - - Object execute(ResolvedJavaMethod method, Object... arguments) throws Throwable; -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/RuntimeInterpreterInterface.java --- a/graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/RuntimeInterpreterInterface.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +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.api.interpreter; - -import com.oracle.graal.api.meta.*; - -/** - * Please note: The parameters of the interface are currently in reversed order since it was derived - * from the java ByteCodeInterpreter implementation. There it was simpler to use the parameters in - * reversed order since they are popped from the stack in reversed order. - */ -public interface RuntimeInterpreterInterface { - - Object invoke(ResolvedJavaMethod method, Object... args); - - void monitorEnter(Object value); - - void monitorExit(Object value); - - Object newObject(ResolvedJavaType type) throws InstantiationException; - - Object getFieldObject(Object base, ResolvedJavaField field); - - boolean getFieldBoolean(Object base, ResolvedJavaField field); - - byte getFieldByte(Object base, ResolvedJavaField field); - - char getFieldChar(Object base, ResolvedJavaField field); - - short getFieldShort(Object base, ResolvedJavaField field); - - int getFieldInt(Object base, ResolvedJavaField field); - - long getFieldLong(Object base, ResolvedJavaField field); - - double getFieldDouble(Object base, ResolvedJavaField field); - - float getFieldFloat(Object base, ResolvedJavaField field); - - void setFieldObject(Object value, Object base, ResolvedJavaField field); - - void setFieldInt(int value, Object base, ResolvedJavaField field); - - void setFieldFloat(float value, Object base, ResolvedJavaField field); - - void setFieldDouble(double value, Object base, ResolvedJavaField field); - - void setFieldLong(long value, Object base, ResolvedJavaField field); - - byte getArrayByte(long index, Object array); - - char getArrayChar(long index, Object array); - - short getArrayShort(long index, Object array); - - int getArrayInt(long index, Object array); - - long getArrayLong(long index, Object array); - - double getArrayDouble(long index, Object array); - - float getArrayFloat(long index, Object array); - - Object getArrayObject(long index, Object array); - - void setArrayByte(byte value, long index, Object array); - - void setArrayChar(char value, long index, Object array); - - void setArrayShort(short value, long index, Object array); - - void setArrayInt(int value, long index, Object array); - - void setArrayLong(long value, long index, Object array); - - void setArrayFloat(float value, long index, Object array); - - void setArrayDouble(double value, long index, Object array); - - void setArrayObject(Object value, long index, Object array); - - Class getMirror(ResolvedJavaType type); -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/VirtualMachineComponent.java --- a/graal/com.oracle.graal.api.interpreter/src/com/oracle/graal/api/interpreter/VirtualMachineComponent.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2012, 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.api.interpreter; - -public interface VirtualMachineComponent { - - void setOption(String name, String value); -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DeoptimizationReason.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DeoptimizationReason.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/DeoptimizationReason.java Mon Feb 04 20:23:57 2013 +0100 @@ -39,5 +39,5 @@ Unresolved, JavaSubroutineMismatch, ArithmeticException, - RuntimeConstraint, + RuntimeConstraint } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java --- a/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.asm/src/com/oracle/graal/asm/AbstractAssembler.java Mon Feb 04 20:23:57 2013 +0100 @@ -22,8 +22,9 @@ */ package com.oracle.graal.asm; +import java.nio.*; + import com.oracle.graal.api.code.*; -import com.oracle.graal.api.code.Architecture.*; /** * The platform-independent base class for the assembler. @@ -36,7 +37,7 @@ public AbstractAssembler(TargetDescription target) { this.target = target; - if (target.arch.getByteOrder() == ByteOrder.BigEndian) { + if (target.arch.getByteOrder() == ByteOrder.BIG_ENDIAN) { this.codeBuffer = new Buffer.BigEndian(); } else { this.codeBuffer = new Buffer.LittleEndian(); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ea/EscapeAnalysisTest.java Mon Feb 04 20:23:57 2013 +0100 @@ -198,7 +198,7 @@ StructuredGraph graph = parse(snippet); try { for (Invoke n : graph.getInvokes()) { - n.node().setProbability(100000); + n.setInliningRelevance(1); } Assumptions assumptions = new Assumptions(false); diff -r ec6dc1326b15 -r 14720c279875 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 Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotGraalRuntime.java Mon Feb 04 20:23:57 2013 +0100 @@ -28,7 +28,6 @@ import java.util.*; import com.oracle.graal.api.code.*; -import com.oracle.graal.api.interpreter.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.api.runtime.*; import com.oracle.graal.compiler.*; @@ -265,9 +264,6 @@ if (clazz == GraalCompiler.class) { return (T) getCompiler(); } - if (clazz == RuntimeInterpreterInterface.class) { - return (T) getRuntimeInterpreterInterface(); - } return null; } } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeInterpreterInterface.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeInterpreterInterface.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotRuntimeInterpreterInterface.java Mon Feb 04 20:23:57 2013 +0100 @@ -28,11 +28,10 @@ import sun.misc.*; -import com.oracle.graal.api.interpreter.*; import com.oracle.graal.api.meta.*; import com.oracle.graal.hotspot.meta.*; -public class HotSpotRuntimeInterpreterInterface implements RuntimeInterpreterInterface { +public class HotSpotRuntimeInterpreterInterface { private final MetaAccessProvider metaProvider; diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java Mon Feb 04 20:23:57 2013 +0100 @@ -27,8 +27,10 @@ import java.lang.reflect.*; import com.oracle.graal.api.meta.*; +import com.oracle.graal.debug.*; import com.oracle.graal.hotspot.*; import com.oracle.graal.phases.*; +import com.oracle.graal.snippets.*; /** * Represents a field in a HotSpot type. @@ -86,10 +88,16 @@ } return constant; } else { + /* + * for non-static final fields, we must assume that they are only initialized if they + * have a non-default value. + */ assert !Modifier.isStatic(flags); - // TODO (chaeubl) HotSpot does not trust final non-static fields (see ciField.cpp) if (Modifier.isFinal(getModifiers())) { - return readValue(receiver); + Constant value = readValue(receiver); + if (assumeNonStaticFinalFieldsAsFinal(receiver.asObject().getClass()) || !value.isDefaultForKind()) { + return value; + } } } return null; @@ -113,6 +121,10 @@ return clazz == GraalOptions.class; } + private static boolean assumeNonStaticFinalFieldsAsFinal(Class clazz) { + return clazz == SnippetCounter.class; + } + @Override public HotSpotResolvedObjectType getDeclaringClass() { return holder; diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/CheckCastSnippets.java Mon Feb 04 20:23:57 2013 +0100 @@ -79,7 +79,7 @@ isNull.inc(); } else { Word objectHub = loadHub(object); - if (objectHub != exactHub) { + if (objectHub.notEqual(exactHub)) { probability(DEOPT_PATH_PROBABILITY); exactMiss.inc(); //bkpt(object, exactHub, objectHub); @@ -108,7 +108,7 @@ isNull.inc(); } else { Word objectHub = loadHub(object); - if (objectHub.readWord(superCheckOffset) != hub) { + if (objectHub.readWord(superCheckOffset).notEqual(hub)) { probability(DEOPT_PATH_PROBABILITY); displayMiss.inc(); DeoptimizeNode.deopt(InvalidateReprofile, ClassCastException); @@ -136,7 +136,7 @@ ExplodeLoopNode.explodeLoop(); for (int i = 0; i < hints.length; i++) { Word hintHub = hints[i]; - if (hintHub == objectHub) { + if (hintHub.equal(objectHub)) { hintsHit.inc(); return unsafeCast(verifyOop(object), StampFactory.forNodeIntrinsic()); } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/ClassSubstitutions.java Mon Feb 04 20:23:57 2013 +0100 @@ -41,7 +41,7 @@ @MethodSubstitution(isStatic = false) public static int getModifiers(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { // Class for primitive type return Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC; } else { @@ -52,7 +52,7 @@ @MethodSubstitution(isStatic = false) public static boolean isInterface(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { return false; } else { int accessFlags = klass.readInt(klassAccessFlagsOffset()); @@ -63,7 +63,7 @@ @MethodSubstitution(isStatic = false) public static boolean isArray(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass == Word.zero()) { + if (klass.equal(0)) { return false; } else { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); @@ -74,13 +74,13 @@ @MethodSubstitution(isStatic = false) public static boolean isPrimitive(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - return klass == Word.zero(); + return klass.equal(0); } @MethodSubstitution(isStatic = false) public static Class getSuperclass(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass != Word.zero()) { + if (klass.notEqual(0)) { int accessFlags = klass.readInt(klassAccessFlagsOffset()); if ((accessFlags & Modifier.INTERFACE) == 0) { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); @@ -88,7 +88,7 @@ return Object.class; } else { Word superKlass = klass.readWord(klassSuperKlassOffset()); - if (superKlass == Word.zero()) { + if (superKlass.equal(0)) { return null; } else { return unsafeCast(superKlass.readObject(classMirrorOffset()), Class.class, true, true); @@ -102,7 +102,7 @@ @MethodSubstitution(isStatic = false) public static Class getComponentType(final Class thisObj) { Word klass = loadWordFromObject(thisObj, klassOffset()); - if (klass != Word.zero()) { + if (klass.notEqual(0)) { int layoutHelper = klass.readInt(klassLayoutHelperOffset()); if ((layoutHelper & arrayKlassLayoutHelperIdentifier()) != 0) { return unsafeCast(klass.readObject(arrayKlassComponentMirrorOffset()), Class.class, true, true); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/HotSpotSnippetUtils.java Mon Feb 04 20:23:57 2013 +0100 @@ -458,7 +458,7 @@ // this code is independent from biased locking (although it does not look that way) final Word biasedLock = mark.and(biasedLockMaskInPlace()); - if (biasedLock == Word.unsigned(unlockedMask())) { + if (biasedLock.equal(Word.unsigned(unlockedMask()))) { probability(FAST_PATH_PROBABILITY); int hash = (int) mark.unsignedShiftRight(identityHashCodeShift()).rawValue(); if (hash != uninitializedIdentityHashCodeValue()) { diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/InstanceOfSnippets.java Mon Feb 04 20:23:57 2013 +0100 @@ -73,7 +73,7 @@ return falseValue; } Word objectHub = loadHub(object); - if (objectHub != exactHub) { + if (objectHub.notEqual(exactHub)) { probability(LIKELY_PROBABILITY); exactMiss.inc(); return falseValue; @@ -99,7 +99,7 @@ return falseValue; } Word objectHub = loadHub(object); - if (objectHub.readWord(superCheckOffset) != hub) { + if (objectHub.readWord(superCheckOffset).notEqual(hub)) { probability(NOT_LIKELY_PROBABILITY); displayMiss.inc(); return falseValue; @@ -129,7 +129,7 @@ ExplodeLoopNode.explodeLoop(); for (int i = 0; i < hints.length; i++) { Word hintHub = hints[i]; - if (hintHub == objectHub) { + if (hintHub.equal(objectHub)) { probability(NOT_FREQUENT_PROBABILITY); hintsHit.inc(); return trueValue; diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/MonitorSnippets.java Mon Feb 04 20:23:57 2013 +0100 @@ -102,7 +102,7 @@ final Word biasableLockBits = mark.and(biasedLockMaskInPlace()); // First check to see whether biasing is enabled for this object - if (biasableLockBits != Word.unsigned(biasedLockPattern())) { + if (biasableLockBits.notEqual(Word.unsigned(biasedLockPattern()))) { // Biasing not enabled -> fall through to lightweight locking } else { probability(FREQUENT_PROBABILITY); @@ -115,7 +115,7 @@ trace(trace, "prototypeMarkWord: 0x%016lx\n", prototypeMarkWord); trace(trace, " thread: 0x%016lx\n", thread); trace(trace, " tmp: 0x%016lx\n", tmp); - if (tmp == Word.zero()) { + if (tmp.equal(0)) { // Object is already biased to current thread -> done probability(FREQUENT_PROBABILITY); traceObject(trace, "+lock{bias:existing}", object); @@ -131,7 +131,7 @@ // If the low three bits in the xor result aren't clear, that means // the prototype header is no longer biasable and we have to revoke // the bias on this object. - if (tmp.and(biasedLockMaskInPlace()) == Word.zero()) { + if (tmp.and(biasedLockMaskInPlace()).equal(0)) { probability(FREQUENT_PROBABILITY); // Biasing is still enabled for object's type. See whether the // epoch of the current bias is still valid, meaning that the epoch @@ -142,7 +142,7 @@ // that the current epoch is invalid in order to do this because // otherwise the manipulations it performs on the mark word are // illegal. - if (tmp.and(epochMaskInPlace()) == Word.zero()) { + if (tmp.and(epochMaskInPlace()).equal(0)) { probability(FREQUENT_PROBABILITY); // The epoch of the current bias is still valid but we know nothing // about the owner; it might be set or it might be clear. Try to @@ -154,7 +154,7 @@ Word biasedMark = unbiasedMark.or(thread); trace(trace, " unbiasedMark: 0x%016lx\n", unbiasedMark); trace(trace, " biasedMark: 0x%016lx\n", biasedMark); - if (compareAndSwap(object, markOffset(), unbiasedMark, biasedMark) == unbiasedMark) { + if (compareAndSwap(object, markOffset(), unbiasedMark, biasedMark).equal(unbiasedMark)) { // Object is now biased to current thread -> done traceObject(trace, "+lock{bias:acquired}", object); return; @@ -175,7 +175,7 @@ // the bias from one thread to another directly in this situation. Word biasedMark = prototypeMarkWord.or(thread); trace(trace, " biasedMark: 0x%016lx\n", biasedMark); - if (compareAndSwap(object, markOffset(), mark, biasedMark) == mark) { + if (compareAndSwap(object, markOffset(), mark, biasedMark).equal(mark)) { // Object is now biased to current thread -> done traceObject(trace, "+lock{bias:transfer}", object); return; @@ -220,7 +220,7 @@ // Test if the object's mark word is unlocked, and if so, store the // (address of) the lock slot into the object's mark word. Word currentMark = compareAndSwap(object, markOffset(), unlockedMark, lock); - if (currentMark != unlockedMark) { + if (currentMark.notEqual(unlockedMark)) { trace(trace, " currentMark: 0x%016lx\n", currentMark); // The mark word in the object header was not the same. // Either the object is locked by another thread or is already locked @@ -239,7 +239,7 @@ // significant 2 bits cleared and page_size is a power of 2 final Word alignedMask = Word.unsigned(wordSize() - 1); final Word stackPointer = stackPointer(); - if (currentMark.subtract(stackPointer).and(alignedMask.subtract(pageSize())) != Word.zero()) { + if (currentMark.subtract(stackPointer).and(alignedMask.subtract(pageSize())).notEqual(0)) { // Most likely not a recursive lock, go into a slow runtime call probability(DEOPT_PATH_PROBABILITY); traceObject(trace, "+lock{stub:failed-cas}", object); @@ -290,7 +290,7 @@ // the bias bit would be clear. final Word mark = loadWordFromObject(object, markOffset()); trace(trace, " mark: 0x%016lx\n", mark); - if (mark.and(biasedLockMaskInPlace()) == Word.unsigned(biasedLockPattern())) { + if (mark.and(biasedLockMaskInPlace()).equal(Word.unsigned(biasedLockPattern()))) { probability(FREQUENT_PROBABILITY); endLockScope(); decCounter(); @@ -305,7 +305,7 @@ final Word displacedMark = lock.readWord(lockDisplacedMarkOffset()); trace(trace, " displacedMark: 0x%016lx\n", displacedMark); - if (displacedMark == Word.zero()) { + if (displacedMark.equal(0)) { // Recursive locking => done traceObject(trace, "-lock{recursive}", object); } else { @@ -313,7 +313,7 @@ // Test if object's mark word is pointing to the displaced mark word, and if so, restore // the displaced mark in the object - if the object's mark word is not pointing to // the displaced mark word, do unlocking via runtime call. - if (DirectCompareAndSwapNode.compareAndSwap(object, markOffset(), lock, displacedMark) != lock) { + if (DirectCompareAndSwapNode.compareAndSwap(object, markOffset(), lock, displacedMark).notEqual(lock)) { // The object's mark word was not pointing to the displaced header, // we do unlocking via runtime call. probability(DEOPT_PATH_PROBABILITY); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/NewObjectSnippets.java Mon Feb 04 20:23:57 2013 +0100 @@ -84,7 +84,7 @@ @ConstantParameter("locked") boolean locked) { Object result; - if (memory == Word.zero()) { + if (memory.equal(0)) { new_stub.inc(); result = NewInstanceStubCall.call(hub); } else { @@ -118,7 +118,7 @@ private static Object initializeArray(Word memory, Word hub, int length, int allocationSize, Word prototypeMarkWord, int headerSize, boolean fillContents) { Object result; - if (memory == Word.zero()) { + if (memory.equal(0)) { newarray_stub.inc(); result = NewArrayStubCall.call(hub, length); } else { diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/snippets/TypeCheckSnippetUtils.java Mon Feb 04 20:23:57 2013 +0100 @@ -41,7 +41,7 @@ static boolean checkSecondarySubType(Word t, Word s) { // if (S.cache == T) return true - if (s.readWord(secondarySuperCacheOffset()) == t) { + if (s.readWord(secondarySuperCacheOffset()).equal(t)) { cacheHit.inc(); return true; } @@ -55,7 +55,7 @@ boolean primary = superCheckOffset != secondarySuperCacheOffset(); // if (T = S[off]) return true - if (s.readWord(superCheckOffset) == t) { + if (s.readWord(superCheckOffset).equal(t)) { if (primary) { cacheHit.inc(); } else { @@ -75,7 +75,7 @@ private static boolean checkSelfAndSupers(Word t, Word s) { // if (T == S) return true - if (s == t) { + if (s.equal(t)) { T_equals_S.inc(); return true; } @@ -84,7 +84,7 @@ Word secondarySupers = s.readWord(secondarySupersOffset()); int length = secondarySupers.readInt(metaspaceArrayLengthOffset()); for (int i = 0; i < length; i++) { - if (t == loadWordElement(secondarySupers, i)) { + if (t.equal(loadWordElement(secondarySupers, i))) { probability(NOT_LIKELY_PROBABILITY); s.writeWord(secondarySuperCacheOffset(), t); secondariesHit.inc(); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewArrayStub.java Mon Feb 04 20:23:57 2013 +0100 @@ -80,7 +80,7 @@ // check that array length is small enough for fast path. if (length <= MAX_ARRAY_FAST_PATH_ALLOCATION_LENGTH) { Word memory = refillAllocate(intArrayHub, sizeInBytes, log); - if (memory != Word.zero()) { + if (memory.notEqual(0)) { log(log, "newArray: allocated new array at %p\n", memory); formatArray(hub, sizeInBytes, length, headerSize, memory, Word.unsigned(arrayPrototypeMarkWord()), true); return verifyOop(memory.toObject()); diff -r ec6dc1326b15 -r 14720c279875 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 Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Mon Feb 04 20:23:57 2013 +0100 @@ -71,7 +71,7 @@ if (!forceSlowPath() && inlineContiguousAllocationSupported()) { if (hub.readInt(klassStateOffset()) == klassStateFullyInitialized()) { Word memory = refillAllocate(intArrayHub, sizeInBytes, log); - if (memory != Word.zero()) { + if (memory.notEqual(0)) { Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset()); memory.writeWord(markOffset(), prototypeMarkWord); memory.writeWord(hubOffset(), hub); @@ -129,7 +129,7 @@ // if TLAB is currently allocated (top or end != null) then // fill [top, end + alignment_reserve) with array object - if (top != Word.zero()) { + if (top.notEqual(0)) { int headerSize = arrayBaseOffset(Kind.Int); // just like the HotSpot assembler stubs, assumes that tlabFreeSpaceInInts fits in // an int @@ -147,7 +147,7 @@ Word tlabRefillSizeInBytes = tlabRefillSizeInWords.multiply(wordSize()); // allocate new TLAB, address returned in top top = edenAllocate(tlabRefillSizeInBytes, log); - if (top != Word.zero()) { + if (top.notEqual(0)) { thread.writeWord(threadTlabStartOffset(), top); thread.writeWord(threadTlabTopOffset(), top); @@ -195,7 +195,7 @@ return Word.zero(); } - if (compareAndSwap(heapTopAddress, 0, heapTop, newHeapTop) == heapTop) { + if (compareAndSwap(heapTopAddress, 0, heapTop, newHeapTop).equal(heapTop)) { return heapTop; } } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/overview.html --- a/graal/com.oracle.graal.interpreter/overview.html Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ - - - - - - - - -Documentation for the com.oracle.graal.interpreter project. - - - diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/BytecodeInterpreter.java --- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/BytecodeInterpreter.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1679 +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.interpreter; - -import java.lang.reflect.*; -import java.util.*; - -import com.oracle.graal.api.interpreter.*; -import com.oracle.graal.api.meta.*; -import com.oracle.graal.api.runtime.*; -import com.oracle.graal.bytecode.*; - -/** - * High-level bytecode interpreter that executes on top of Java. Java native methods are executed - * using the {@link com.oracle.graal.api.interpreter.RuntimeInterpreterInterface}. - */ -@SuppressWarnings("static-method") -public final class BytecodeInterpreter implements Interpreter { - - private static final String OPTION_MAX_STACK_SIZE = "maxStackSize"; - private static final boolean TRACE = false; - private static final boolean TRACE_BYTE_CODE = false; - - private static final int DEFAULT_MAX_STACK_SIZE = 1500; - - private static final int NEXT = -1; - private static final int BRANCH = -2; - private static final int RETURN = -3; - private static final int CALL = -4; - - private InterpreterFrame callFrame; - - private Map methodDelegates; - - private int maxStackFrames; - - private ResolvedJavaMethod rootMethod; - private RuntimeInterpreterInterface runtimeInterface; - private MetaAccessProvider metaAccessProvider; - - public boolean initialize(String args) { - methodDelegates = new HashMap<>(); - maxStackFrames = DEFAULT_MAX_STACK_SIZE; - - GraalRuntime runtime = Graal.getRuntime(); - this.runtimeInterface = runtime.getCapability(RuntimeInterpreterInterface.class); - if (this.runtimeInterface == null) { - throw new UnsupportedOperationException("The provided Graal runtime does not support the required capability " + RuntimeInterpreterInterface.class.getName() + "."); - } - this.metaAccessProvider = runtime.getCapability(MetaAccessProvider.class); - if (this.metaAccessProvider == null) { - throw new UnsupportedOperationException("The provided Graal runtime does not support the required capability " + MetaAccessProvider.class.getName() + "."); - } - - this.rootMethod = resolveRootMethod(); - registerDelegates(); - return parseArguments(args); - } - - @Override - public void setOption(String name, String value) { - if (name != null && name.equals(OPTION_MAX_STACK_SIZE)) { - this.maxStackFrames = Integer.parseInt(value); - } - } - - private void registerDelegates() { - addDelegate(findMethod(Throwable.class, "fillInStackTrace"), new InterpreterCallable() { - - @Override - public Object invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object[] arguments) throws Throwable { - setBackTrace(caller, (Throwable) arguments[0], createStackTraceElements(caller, runtimeInterface)); - return null; - } - }); - addDelegate(findMethod(Throwable.class, "getStackTraceDepth"), new InterpreterCallable() { - - @Override - public Object invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object[] arguments) throws Throwable { - StackTraceElement[] elements = getBackTrace(caller, (Throwable) arguments[0]); - if (elements != null) { - return elements.length; - } - return 0; - } - }); - addDelegate(findMethod(Throwable.class, "getStackTraceElement", int.class), new InterpreterCallable() { - - @Override - public Object invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object[] arguments) throws Throwable { - StackTraceElement[] elements = getBackTrace(caller, (Throwable) arguments[0]); - if (elements != null) { - Integer index = (Integer) arguments[0]; - if (index != null) { - return elements[index]; - } - } - return null; - } - }); - } - - @SuppressWarnings("unused") - private boolean parseArguments(String stringArgs) { - // TODO: parse the arguments - return true; - } - - public void setMaxStackFrames(int maxStackSize) { - this.maxStackFrames = maxStackSize; - } - - public int getMaxStackFrames() { - return maxStackFrames; - } - - public void addDelegate(Method method, InterpreterCallable callable) { - ResolvedJavaMethod resolvedMethod = metaAccessProvider.lookupJavaMethod(method); - if (methodDelegates.containsKey(resolvedMethod)) { - throw new IllegalArgumentException("Delegate for method " + method + " already added."); - } - - methodDelegates.put(resolvedMethod, new MethodRedirectionInfo(callable)); - } - - public void removeDelegate(Method method) { - methodDelegates.remove(metaAccessProvider.lookupJavaMethod(method)); - } - - @Override - public Object execute(ResolvedJavaMethod method, Object... boxedArguments) throws Throwable { - try { - boolean receiver = hasReceiver(method); - Signature signature = method.getSignature(); - assert boxedArguments != null; - assert signature.getParameterCount(receiver) == boxedArguments.length; - - if (TRACE) { - trace(0, "Executing root method " + method); - } - - InterpreterFrame rootFrame = new InterpreterFrame(rootMethod, signature.getParameterSlots(true)); - rootFrame.pushObject(this); - rootFrame.pushObject(method); - rootFrame.pushObject(boxedArguments); - - int index = 0; - if (receiver) { - pushAsObject(rootFrame, Kind.Object, boxedArguments[index]); - index++; - } - - for (int i = 0; index < boxedArguments.length; i++, index++) { - pushAsObject(rootFrame, signature.getParameterKind(i), boxedArguments[index]); - } - - InterpreterFrame frame = rootFrame.create(method, receiver); - executeRoot(rootFrame, frame); - return popAsObject(rootFrame, signature.getReturnKind()); - } catch (Exception e) { - // TODO (chaeubl): remove this exception handler (only used for debugging) - throw e; - } - } - - public Object execute(Method javaMethod, Object... boxedArguments) throws Throwable { - return execute(metaAccessProvider.lookupJavaMethod(javaMethod), boxedArguments); - } - - private boolean hasReceiver(ResolvedJavaMethod method) { - return !Modifier.isStatic(method.getModifiers()); - } - - private void executeRoot(InterpreterFrame root, InterpreterFrame frame) throws Throwable { - // TODO reflection redirection - InterpreterFrame prevFrame = frame; - InterpreterFrame currentFrame = frame; - BytecodeStream bs = new BytecodeStream(currentFrame.getMethod().getCode()); - if (TRACE) { - traceCall(frame, "Call"); - } - while (currentFrame != root) { - if (prevFrame != currentFrame) { - bs = new BytecodeStream(currentFrame.getMethod().getCode()); - } - bs.setBCI(currentFrame.getBCI()); - - prevFrame = currentFrame; - currentFrame = loop(root, prevFrame, bs); - } - assert callFrame == null; - } - - private InterpreterFrame loop(InterpreterFrame root, final InterpreterFrame frame, final BytecodeStream bs) throws Throwable { - try { - while (true) { - int result = executeInstruction(frame, bs); - switch (result) { - case NEXT: - bs.next(); - break; - case RETURN: - return popFrame(frame); - case CALL: - return allocateFrame(frame, bs); - case BRANCH: - bs.setBCI(bs.readBranchDest()); - break; - default: - // the outcome depends on stack values - assert result >= 0 : "negative branch target"; - bs.setBCI(result); - break; - } - } - } catch (Throwable t) { - if (TRACE) { - traceOp(frame, "Exception " + t.toString()); - } - updateStackTrace(frame, t); - - // frame bci needs to be in sync when handling exceptions - frame.setBCI(bs.currentBCI()); - - InterpreterFrame handlerFrame = handleThrowable(root, frame, t); - if (handlerFrame == null) { - // matched root we just throw it again. - throw t; - } else { - if (TRACE) { - traceOp(frame, "Handler found " + handlerFrame.getMethod() + ":" + handlerFrame.getBCI()); - } - // update bci from frame - bs.setBCI(handlerFrame.getBCI()); - - // continue execution on the found frame - return handlerFrame; - } - } finally { - // TODO may be not necessary. - frame.setBCI(bs.currentBCI()); - } - } - - private int executeInstruction(InterpreterFrame frame, BytecodeStream bs) throws Throwable { - if (TRACE_BYTE_CODE) { - traceOp(frame, bs.currentBCI() + ": " + Bytecodes.baseNameOf(bs.currentBC())); - } - switch (bs.currentBC()) { - case Bytecodes.NOP: - break; - case Bytecodes.ACONST_NULL: - frame.pushObject(null); - break; - case Bytecodes.ICONST_M1: - frame.pushInt(-1); - break; - case Bytecodes.ICONST_0: - frame.pushInt(0); - break; - case Bytecodes.ICONST_1: - frame.pushInt(1); - break; - case Bytecodes.ICONST_2: - frame.pushInt(2); - break; - case Bytecodes.ICONST_3: - frame.pushInt(3); - break; - case Bytecodes.ICONST_4: - frame.pushInt(4); - break; - case Bytecodes.ICONST_5: - frame.pushInt(5); - break; - case Bytecodes.LCONST_0: - frame.pushLong(0L); - break; - case Bytecodes.LCONST_1: - frame.pushLong(1L); - break; - case Bytecodes.FCONST_0: - frame.pushFloat(0.0F); - break; - case Bytecodes.FCONST_1: - frame.pushFloat(1.0F); - break; - case Bytecodes.FCONST_2: - frame.pushFloat(2.0F); - break; - case Bytecodes.DCONST_0: - frame.pushDouble(0.0D); - break; - case Bytecodes.DCONST_1: - frame.pushDouble(1.0D); - break; - case Bytecodes.BIPUSH: - frame.pushInt(bs.readByte()); - break; - case Bytecodes.SIPUSH: - frame.pushInt(bs.readShort()); - break; - case Bytecodes.LDC: - case Bytecodes.LDC_W: - case Bytecodes.LDC2_W: - pushCPConstant(frame, bs.readCPI()); - break; - case Bytecodes.ILOAD: - frame.pushInt(frame.getInt(frame.resolveLocalIndex(bs.readLocalIndex()))); - break; - case Bytecodes.LLOAD: - frame.pushLong(frame.getLong(frame.resolveLocalIndex(bs.readLocalIndex()))); - break; - case Bytecodes.FLOAD: - frame.pushFloat(frame.getFloat(frame.resolveLocalIndex(bs.readLocalIndex()))); - break; - case Bytecodes.DLOAD: - frame.pushDouble(frame.getDouble(frame.resolveLocalIndex(bs.readLocalIndex()))); - break; - case Bytecodes.ALOAD: - frame.pushObject(frame.getObject(frame.resolveLocalIndex(bs.readLocalIndex()))); - break; - case Bytecodes.ILOAD_0: - frame.pushInt(frame.getInt(frame.resolveLocalIndex(0))); - break; - case Bytecodes.ILOAD_1: - frame.pushInt(frame.getInt(frame.resolveLocalIndex(1))); - break; - case Bytecodes.ILOAD_2: - frame.pushInt(frame.getInt(frame.resolveLocalIndex(2))); - break; - case Bytecodes.ILOAD_3: - frame.pushInt(frame.getInt(frame.resolveLocalIndex(3))); - break; - case Bytecodes.LLOAD_0: - frame.pushLong(frame.getLong(frame.resolveLocalIndex(0))); - break; - case Bytecodes.LLOAD_1: - frame.pushLong(frame.getLong(frame.resolveLocalIndex(1))); - break; - case Bytecodes.LLOAD_2: - frame.pushLong(frame.getLong(frame.resolveLocalIndex(2))); - break; - case Bytecodes.LLOAD_3: - frame.pushLong(frame.getLong(frame.resolveLocalIndex(3))); - break; - case Bytecodes.FLOAD_0: - frame.pushFloat(frame.getFloat(frame.resolveLocalIndex(0))); - break; - case Bytecodes.FLOAD_1: - frame.pushFloat(frame.getFloat(frame.resolveLocalIndex(1))); - break; - case Bytecodes.FLOAD_2: - frame.pushFloat(frame.getFloat(frame.resolveLocalIndex(2))); - break; - case Bytecodes.FLOAD_3: - frame.pushFloat(frame.getFloat(frame.resolveLocalIndex(3))); - break; - case Bytecodes.DLOAD_0: - frame.pushDouble(frame.getDouble(frame.resolveLocalIndex(0))); - break; - case Bytecodes.DLOAD_1: - frame.pushDouble(frame.getDouble(frame.resolveLocalIndex(1))); - break; - case Bytecodes.DLOAD_2: - frame.pushDouble(frame.getDouble(frame.resolveLocalIndex(2))); - break; - case Bytecodes.DLOAD_3: - frame.pushDouble(frame.getDouble(frame.resolveLocalIndex(3))); - break; - case Bytecodes.ALOAD_0: - frame.pushObject(frame.getObject(frame.resolveLocalIndex(0))); - break; - case Bytecodes.ALOAD_1: - frame.pushObject(frame.getObject(frame.resolveLocalIndex(1))); - break; - case Bytecodes.ALOAD_2: - frame.pushObject(frame.getObject(frame.resolveLocalIndex(2))); - break; - case Bytecodes.ALOAD_3: - frame.pushObject(frame.getObject(frame.resolveLocalIndex(3))); - break; - case Bytecodes.IALOAD: - frame.pushInt(runtimeInterface.getArrayInt(frame.popInt(), frame.popObject())); - break; - case Bytecodes.LALOAD: - frame.pushLong(runtimeInterface.getArrayLong(frame.popInt(), frame.popObject())); - break; - case Bytecodes.FALOAD: - frame.pushFloat(runtimeInterface.getArrayFloat(frame.popInt(), frame.popObject())); - break; - case Bytecodes.DALOAD: - frame.pushDouble(runtimeInterface.getArrayDouble(frame.popInt(), frame.popObject())); - break; - case Bytecodes.AALOAD: - frame.pushObject(runtimeInterface.getArrayObject(frame.popInt(), frame.popObject())); - break; - case Bytecodes.BALOAD: - frame.pushInt(runtimeInterface.getArrayByte(frame.popInt(), frame.popObject())); - break; - case Bytecodes.CALOAD: - frame.pushInt(runtimeInterface.getArrayChar(frame.popInt(), frame.popObject())); - break; - case Bytecodes.SALOAD: - frame.pushInt(runtimeInterface.getArrayShort(frame.popInt(), frame.popObject())); - break; - case Bytecodes.ISTORE: - frame.setInt(frame.resolveLocalIndex(bs.readLocalIndex()), frame.popInt()); - break; - case Bytecodes.LSTORE: - frame.setLong(frame.resolveLocalIndex(bs.readLocalIndex()), frame.popLong()); - break; - case Bytecodes.FSTORE: - frame.setFloat(frame.resolveLocalIndex(bs.readLocalIndex()), frame.popFloat()); - break; - case Bytecodes.DSTORE: - frame.setDouble(frame.resolveLocalIndex(bs.readLocalIndex()), frame.popDouble()); - break; - case Bytecodes.ASTORE: - frame.setObject(frame.resolveLocalIndex(bs.readLocalIndex()), frame.popObject()); - break; - case Bytecodes.ISTORE_0: - frame.setInt(frame.resolveLocalIndex(0), frame.popInt()); - break; - case Bytecodes.ISTORE_1: - frame.setInt(frame.resolveLocalIndex(1), frame.popInt()); - break; - case Bytecodes.ISTORE_2: - frame.setInt(frame.resolveLocalIndex(2), frame.popInt()); - break; - case Bytecodes.ISTORE_3: - frame.setInt(frame.resolveLocalIndex(3), frame.popInt()); - break; - case Bytecodes.LSTORE_0: - frame.setLong(frame.resolveLocalIndex(0), frame.popLong()); - break; - case Bytecodes.LSTORE_1: - frame.setLong(frame.resolveLocalIndex(1), frame.popLong()); - break; - case Bytecodes.LSTORE_2: - frame.setLong(frame.resolveLocalIndex(2), frame.popLong()); - break; - case Bytecodes.LSTORE_3: - frame.setLong(frame.resolveLocalIndex(3), frame.popLong()); - break; - case Bytecodes.FSTORE_0: - frame.setFloat(frame.resolveLocalIndex(0), frame.popFloat()); - break; - case Bytecodes.FSTORE_1: - frame.setFloat(frame.resolveLocalIndex(1), frame.popFloat()); - break; - case Bytecodes.FSTORE_2: - frame.setFloat(frame.resolveLocalIndex(2), frame.popFloat()); - break; - case Bytecodes.FSTORE_3: - frame.setFloat(frame.resolveLocalIndex(3), frame.popFloat()); - break; - case Bytecodes.DSTORE_0: - frame.setDouble(frame.resolveLocalIndex(0), frame.popDouble()); - break; - case Bytecodes.DSTORE_1: - frame.setDouble(frame.resolveLocalIndex(1), frame.popDouble()); - break; - case Bytecodes.DSTORE_2: - frame.setDouble(frame.resolveLocalIndex(2), frame.popDouble()); - break; - case Bytecodes.DSTORE_3: - frame.setDouble(frame.resolveLocalIndex(3), frame.popDouble()); - break; - case Bytecodes.ASTORE_0: - frame.setObject(frame.resolveLocalIndex(0), frame.popObject()); - break; - case Bytecodes.ASTORE_1: - frame.setObject(frame.resolveLocalIndex(1), frame.popObject()); - break; - case Bytecodes.ASTORE_2: - frame.setObject(frame.resolveLocalIndex(2), frame.popObject()); - break; - case Bytecodes.ASTORE_3: - frame.setObject(frame.resolveLocalIndex(3), frame.popObject()); - break; - case Bytecodes.IASTORE: - runtimeInterface.setArrayInt(frame.popInt(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.LASTORE: - runtimeInterface.setArrayLong(frame.popLong(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.FASTORE: - runtimeInterface.setArrayFloat(frame.popFloat(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.DASTORE: - runtimeInterface.setArrayDouble(frame.popDouble(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.AASTORE: - runtimeInterface.setArrayObject(frame.popObject(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.BASTORE: - runtimeInterface.setArrayByte((byte) frame.popInt(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.CASTORE: - runtimeInterface.setArrayChar((char) frame.popInt(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.SASTORE: - runtimeInterface.setArrayShort((short) frame.popInt(), frame.popInt(), frame.popObject()); - break; - case Bytecodes.POP: - frame.popVoid(1); - break; - case Bytecodes.POP2: - frame.popVoid(2); - break; - case Bytecodes.DUP: - frame.dup(1); - break; - case Bytecodes.DUP_X1: - frame.dupx1(); - break; - case Bytecodes.DUP_X2: - frame.dupx2(); - break; - case Bytecodes.DUP2: - frame.dup(2); - break; - case Bytecodes.DUP2_X1: - frame.dup2x1(); - break; - case Bytecodes.DUP2_X2: - frame.dup2x2(); - break; - case Bytecodes.SWAP: - frame.swapSingle(); - break; - case Bytecodes.IADD: - frame.pushInt(frame.popInt() + frame.popInt()); - break; - case Bytecodes.LADD: - frame.pushLong(frame.popLong() + frame.popLong()); - break; - case Bytecodes.FADD: - frame.pushFloat(frame.popFloat() + frame.popFloat()); - break; - case Bytecodes.DADD: - frame.pushDouble(frame.popDouble() + frame.popDouble()); - break; - case Bytecodes.ISUB: - frame.pushInt(-frame.popInt() + frame.popInt()); - break; - case Bytecodes.LSUB: - frame.pushLong(-frame.popLong() + frame.popLong()); - break; - case Bytecodes.FSUB: - frame.pushFloat(-frame.popFloat() + frame.popFloat()); - break; - case Bytecodes.DSUB: - frame.pushDouble(-frame.popDouble() + frame.popDouble()); - break; - case Bytecodes.IMUL: - frame.pushInt(frame.popInt() * frame.popInt()); - break; - case Bytecodes.LMUL: - frame.pushLong(frame.popLong() * frame.popLong()); - break; - case Bytecodes.FMUL: - frame.pushFloat(frame.popFloat() * frame.popFloat()); - break; - case Bytecodes.DMUL: - frame.pushDouble(frame.popDouble() * frame.popDouble()); - break; - case Bytecodes.IDIV: - divInt(frame); - break; - case Bytecodes.LDIV: - divLong(frame); - break; - case Bytecodes.FDIV: - divFloat(frame); - break; - case Bytecodes.DDIV: - divDouble(frame); - break; - case Bytecodes.IREM: - remInt(frame); - break; - case Bytecodes.LREM: - remLong(frame); - break; - case Bytecodes.FREM: - remFloat(frame); - break; - case Bytecodes.DREM: - remDouble(frame); - break; - case Bytecodes.INEG: - frame.pushInt(-frame.popInt()); - break; - case Bytecodes.LNEG: - frame.pushLong(-frame.popLong()); - break; - case Bytecodes.FNEG: - frame.pushFloat(-frame.popFloat()); - break; - case Bytecodes.DNEG: - frame.pushDouble(-frame.popDouble()); - break; - case Bytecodes.ISHL: - shiftLeftInt(frame); - break; - case Bytecodes.LSHL: - shiftLeftLong(frame); - break; - case Bytecodes.ISHR: - shiftRightSignedInt(frame); - break; - case Bytecodes.LSHR: - shiftRightSignedLong(frame); - break; - case Bytecodes.IUSHR: - shiftRightUnsignedInt(frame); - break; - case Bytecodes.LUSHR: - shiftRightUnsignedLong(frame); - break; - case Bytecodes.IAND: - frame.pushInt(frame.popInt() & frame.popInt()); - break; - case Bytecodes.LAND: - frame.pushLong(frame.popLong() & frame.popLong()); - break; - case Bytecodes.IOR: - frame.pushInt(frame.popInt() | frame.popInt()); - break; - case Bytecodes.LOR: - frame.pushLong(frame.popLong() | frame.popLong()); - break; - case Bytecodes.IXOR: - frame.pushInt(frame.popInt() ^ frame.popInt()); - break; - case Bytecodes.LXOR: - frame.pushLong(frame.popLong() ^ frame.popLong()); - break; - case Bytecodes.IINC: - iinc(frame, bs); - break; - case Bytecodes.I2L: - frame.pushLong(frame.popInt()); - break; - case Bytecodes.I2F: - frame.pushFloat(frame.popInt()); - break; - case Bytecodes.I2D: - frame.pushDouble(frame.popInt()); - break; - case Bytecodes.L2I: - frame.pushInt((int) frame.popLong()); - break; - case Bytecodes.L2F: - frame.pushFloat(frame.popLong()); - break; - case Bytecodes.L2D: - frame.pushDouble(frame.popLong()); - break; - case Bytecodes.F2I: - frame.pushInt((int) frame.popFloat()); - break; - case Bytecodes.F2L: - frame.pushLong((long) frame.popFloat()); - break; - case Bytecodes.F2D: - frame.pushDouble(frame.popFloat()); - break; - case Bytecodes.D2I: - frame.pushInt((int) frame.popDouble()); - break; - case Bytecodes.D2L: - frame.pushLong((long) frame.popDouble()); - break; - case Bytecodes.D2F: - frame.pushFloat((float) frame.popDouble()); - break; - case Bytecodes.I2B: - frame.pushInt((byte) frame.popInt()); - break; - case Bytecodes.I2C: - frame.pushInt((char) frame.popInt()); - break; - case Bytecodes.I2S: - frame.pushInt((short) frame.popInt()); - break; - case Bytecodes.LCMP: - compareLong(frame); - break; - case Bytecodes.FCMPL: - compareFloatLess(frame); - break; - case Bytecodes.FCMPG: - compareFloatGreater(frame); - break; - case Bytecodes.DCMPL: - compareDoubleLess(frame); - break; - case Bytecodes.DCMPG: - compareDoubleGreater(frame); - break; - case Bytecodes.IFEQ: - if (frame.popInt() == 0) { - return BRANCH; - } - break; - case Bytecodes.IFNE: - if (frame.popInt() != 0) { - return BRANCH; - } - break; - case Bytecodes.IFLT: - if (frame.popInt() < 0) { - return BRANCH; - } - break; - case Bytecodes.IFGE: - if (frame.popInt() >= 0) { - return BRANCH; - } - break; - case Bytecodes.IFGT: - if (frame.popInt() > 0) { - return BRANCH; - } - break; - case Bytecodes.IFLE: - if (frame.popInt() <= 0) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPEQ: - if (frame.popInt() == frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPNE: - if (frame.popInt() != frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPLT: - if (frame.popInt() > frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPGE: - if (frame.popInt() <= frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPGT: - if (frame.popInt() < frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ICMPLE: - if (frame.popInt() >= frame.popInt()) { - return BRANCH; - } - break; - case Bytecodes.IF_ACMPEQ: - if (frame.popObject() == frame.popObject()) { - return BRANCH; - } - break; - case Bytecodes.IF_ACMPNE: - if (frame.popObject() != frame.popObject()) { - return BRANCH; - } - break; - case Bytecodes.GOTO: - case Bytecodes.GOTO_W: - return BRANCH; - case Bytecodes.JSR: - case Bytecodes.JSR_W: - frame.pushInt(bs.currentBCI()); - return BRANCH; - case Bytecodes.RET: - return frame.getInt(frame.resolveLocalIndex(bs.readLocalIndex())); - case Bytecodes.TABLESWITCH: - return tableSwitch(frame, bs); - case Bytecodes.LOOKUPSWITCH: - return lookupSwitch(frame, bs); - case Bytecodes.IRETURN: - frame.getParentFrame().pushInt(frame.popInt()); - return RETURN; - case Bytecodes.LRETURN: - frame.getParentFrame().pushLong(frame.popLong()); - return RETURN; - case Bytecodes.FRETURN: - frame.getParentFrame().pushFloat(frame.popFloat()); - return RETURN; - case Bytecodes.DRETURN: - frame.getParentFrame().pushDouble(frame.popDouble()); - return RETURN; - case Bytecodes.ARETURN: - frame.getParentFrame().pushObject(frame.popObject()); - return RETURN; - case Bytecodes.RETURN: - return RETURN; - case Bytecodes.GETSTATIC: - getField(frame, null, bs.currentBC(), bs.readCPI()); - break; - case Bytecodes.PUTSTATIC: - putStatic(frame, bs.readCPI()); - break; - case Bytecodes.GETFIELD: - getField(frame, nullCheck(frame.popObject()), bs.currentBC(), bs.readCPI()); - break; - case Bytecodes.PUTFIELD: - putField(frame, bs.readCPI()); - break; - case Bytecodes.INVOKEVIRTUAL: - callFrame = invokeVirtual(frame, bs.readCPI()); - if (callFrame == null) { - break; - } - return CALL; - case Bytecodes.INVOKESPECIAL: - callFrame = invokeSpecial(frame, bs.readCPI()); - if (callFrame == null) { - break; - } - return CALL; - case Bytecodes.INVOKESTATIC: - callFrame = invokeStatic(frame, bs.readCPI()); - if (callFrame == null) { - break; - } - return CALL; - case Bytecodes.INVOKEINTERFACE: - callFrame = invokeInterface(frame, bs.readCPI()); - if (callFrame == null) { - break; - } - return CALL; - case Bytecodes.XXXUNUSEDXXX: - assert false : "unused bytecode used. behaviour unspecified."; - // nop - break; - case Bytecodes.NEW: - frame.pushObject(allocateInstance(frame, bs.readCPI())); - break; - case Bytecodes.NEWARRAY: - frame.pushObject(allocateNativeArray(frame, bs.readByte())); - break; - case Bytecodes.ANEWARRAY: - frame.pushObject(allocateArray(frame, bs.readCPI())); - break; - case Bytecodes.ARRAYLENGTH: - frame.pushInt(Array.getLength(nullCheck(frame.popObject()))); - break; - case Bytecodes.ATHROW: - Throwable t = (Throwable) frame.popObject(); - if ("break".equals(t.getMessage())) { - t.printStackTrace(); - } - throw t; - case Bytecodes.CHECKCAST: - checkCast(frame, bs.readCPI()); - break; - case Bytecodes.INSTANCEOF: - instanceOf(frame, bs.readCPI()); - break; - case Bytecodes.MONITORENTER: - runtimeInterface.monitorEnter(frame.popObject()); - break; - case Bytecodes.MONITOREXIT: - runtimeInterface.monitorExit(frame.popObject()); - break; - case Bytecodes.WIDE: - assert false; - break; - case Bytecodes.MULTIANEWARRAY: - frame.pushObject(allocateMultiArray(frame, bs.readCPI(), bs.readUByte(bs.currentBCI() + 3))); - break; - case Bytecodes.IFNULL: - if (frame.popObject() == null) { - return BRANCH; - } - break; - case Bytecodes.IFNONNULL: - if (frame.popObject() != null) { - return BRANCH; - } - break; - case Bytecodes.BREAKPOINT: - assert false : "no breakpoints supported at this time."; - break; // nop - } - return NEXT; - } - - private InterpreterFrame handleThrowable(InterpreterFrame root, InterpreterFrame frame, Throwable t) { - ExceptionHandler handler; - InterpreterFrame currentFrame = frame; - do { - handler = resolveExceptionHandlers(currentFrame, currentFrame.getBCI(), t); - if (handler == null) { - // no handler found pop frame - // and continue searching - currentFrame = popFrame(currentFrame); - } else { - // found a handler -> execute it - currentFrame.setBCI(handler.getHandlerBCI()); - currentFrame.popStack(); - currentFrame.pushObject(t); - return currentFrame; - } - } while (handler == null && currentFrame != root); - - // will throw exception up the interpreter - return null; - } - - private void updateStackTrace(InterpreterFrame frame, Throwable t) { - StackTraceElement[] elements = getBackTrace(frame, t); - if (elements != null) { - setStackTrace(frame, t, elements); - setBackTrace(frame, t, null); - } else { - setBackTrace(frame, t, createStackTraceElements(frame, runtimeInterface)); - } - } - - private void setStackTrace(InterpreterFrame frame, Throwable t, StackTraceElement[] stackTrace) { - runtimeInterface.setFieldObject(stackTrace, t, findThrowableField(frame, "stackTrace")); - } - - private StackTraceElement[] getBackTrace(InterpreterFrame frame, Throwable t) { - Object value = runtimeInterface.getFieldObject(t, findThrowableField(frame, "backtrace")); - if (value instanceof StackTraceElement[]) { - return (StackTraceElement[]) value; - } - return null; - } - - private void setBackTrace(InterpreterFrame frame, Throwable t, StackTraceElement[] backtrace) { - runtimeInterface.setFieldObject(backtrace, t, findThrowableField(frame, "backtrace")); - } - - private ExceptionHandler resolveExceptionHandlers(InterpreterFrame frame, int bci, Throwable t) { - ExceptionHandler[] handlers = frame.getMethod().getExceptionHandlers(); - for (int i = 0; i < handlers.length; i++) { - ExceptionHandler handler = handlers[i]; - if (bci >= handler.getStartBCI() && bci <= handler.getEndBCI()) { - ResolvedJavaType catchType = null; - if (!handler.isCatchAll()) { - // exception handlers are similar to instanceof bytecodes, so we pass instanceof - catchType = resolveType(frame, Bytecodes.INSTANCEOF, (char) handler.catchTypeCPI()); - } - - if (catchType == null || catchType.isInstance(Constant.forObject(t))) { - // the first found exception handler is our exception handler - return handler; - } - } - } - return null; - } - - private Class mirror(ResolvedJavaType type) { - return runtimeInterface.getMirror(type); - } - - private InterpreterFrame allocateFrame(InterpreterFrame frame, BytecodeStream bs) { - try { - InterpreterFrame nextFrame = this.callFrame; - - assert nextFrame != null; - assert nextFrame.getParentFrame() == frame; - - // store bci when leaving method - frame.setBCI(bs.currentBCI()); - - if (TRACE) { - traceCall(nextFrame, "Call"); - } - if (Modifier.isSynchronized(nextFrame.getMethod().getModifiers())) { - if (TRACE) { - traceOp(frame, "Method monitor enter"); - } - if (Modifier.isStatic(nextFrame.getMethod().getModifiers())) { - runtimeInterface.monitorEnter(mirror(nextFrame.getMethod().getDeclaringClass())); - } else { - Object enterObject = nextFrame.getObject(frame.resolveLocalIndex(0)); - assert enterObject != null; - runtimeInterface.monitorEnter(enterObject); - } - } - - return nextFrame; - } finally { - callFrame = null; - bs.next(); - } - } - - private InterpreterFrame popFrame(InterpreterFrame frame) { - InterpreterFrame parent = frame.getParentFrame(); - if (Modifier.isSynchronized(frame.getMethod().getModifiers())) { - if (TRACE) { - traceOp(frame, "Method monitor exit"); - } - if (Modifier.isStatic(frame.getMethod().getModifiers())) { - runtimeInterface.monitorExit(mirror(frame.getMethod().getDeclaringClass())); - } else { - Object exitObject = frame.getObject(frame.resolveLocalIndex(0)); - if (exitObject != null) { - runtimeInterface.monitorExit(exitObject); - } - } - } - if (TRACE) { - traceCall(frame, "Ret"); - } - - frame.dispose(); - return parent; - } - - private void traceOp(InterpreterFrame frame, String opName) { - trace(frame.depth(), opName); - } - - private void traceCall(InterpreterFrame frame, String type) { - trace(frame.depth(), type + " " + frame.getMethod() + " - " + frame.getMethod().getSignature()); - } - - private void trace(int level, String message) { - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < level; i++) { - builder.append(" "); - } - builder.append(message); - System.out.println(builder); - } - - private void divInt(InterpreterFrame frame) { - int dividend = frame.popInt(); - int divisor = frame.popInt(); - frame.pushInt(divisor / dividend); - } - - private void divLong(InterpreterFrame frame) { - long dividend = frame.popLong(); - long divisor = frame.popLong(); - frame.pushLong(divisor / dividend); - } - - private void divFloat(InterpreterFrame frame) { - float dividend = frame.popFloat(); - float divisor = frame.popFloat(); - frame.pushFloat(divisor / dividend); - } - - private void divDouble(InterpreterFrame frame) { - double dividend = frame.popDouble(); - double divisor = frame.popDouble(); - frame.pushDouble(divisor / dividend); - } - - private void remInt(InterpreterFrame frame) { - int dividend = frame.popInt(); - int divisor = frame.popInt(); - frame.pushInt(divisor % dividend); - } - - private void remLong(InterpreterFrame frame) { - long dividend = frame.popLong(); - long divisor = frame.popLong(); - frame.pushLong(divisor % dividend); - } - - private void remFloat(InterpreterFrame frame) { - float dividend = frame.popFloat(); - float divisor = frame.popFloat(); - frame.pushFloat(divisor % dividend); - } - - private void remDouble(InterpreterFrame frame) { - double dividend = frame.popDouble(); - double divisor = frame.popDouble(); - frame.pushDouble(divisor % dividend); - } - - private void shiftLeftInt(InterpreterFrame frame) { - int bits = frame.popInt(); - int value = frame.popInt(); - frame.pushInt(value << bits); - } - - private void shiftLeftLong(InterpreterFrame frame) { - int bits = frame.popInt(); - long value = frame.popLong(); - frame.pushLong(value << bits); - } - - private void shiftRightSignedInt(InterpreterFrame frame) { - int bits = frame.popInt(); - int value = frame.popInt(); - frame.pushInt(value >> bits); - } - - private void shiftRightSignedLong(InterpreterFrame frame) { - int bits = frame.popInt(); - long value = frame.popLong(); - frame.pushLong(value >> bits); - } - - private void shiftRightUnsignedInt(InterpreterFrame frame) { - int bits = frame.popInt(); - int value = frame.popInt(); - frame.pushInt(value >>> bits); - } - - private void shiftRightUnsignedLong(InterpreterFrame frame) { - int bits = frame.popInt(); - long value = frame.popLong(); - frame.pushLong(value >>> bits); - } - - private int lookupSwitch(InterpreterFrame frame, BytecodeStream bs) { - return lookupSearch(new BytecodeLookupSwitch(bs, bs.currentBCI()), frame.popInt()); - } - - /** - * Binary search implementation for the lookup switch. - */ - private int lookupSearch(BytecodeLookupSwitch switchHelper, int key) { - int low = 0; - int high = switchHelper.numberOfCases() - 1; - while (low <= high) { - int mid = (low + high) >>> 1; - int midVal = switchHelper.keyAt(mid); - - if (midVal < key) { - low = mid + 1; - } else if (midVal > key) { - high = mid - 1; - } else { - return switchHelper.bci() + switchHelper.offsetAt(mid); // key found - } - } - return switchHelper.defaultTarget(); // key not found. - } - - private int tableSwitch(InterpreterFrame frame, BytecodeStream bs) { - BytecodeTableSwitch switchHelper = new BytecodeTableSwitch(bs, bs.currentBCI()); - - int low = switchHelper.lowKey(); - int high = switchHelper.highKey(); - - assert low <= high; - - int index = frame.popInt(); - if (index < low || index > high) { - return switchHelper.defaultTarget(); - } else { - return switchHelper.targetAt(index - low); - } - } - - private void checkCast(InterpreterFrame frame, char cpi) { - frame.pushObject(mirror(resolveType(frame, Bytecodes.CHECKCAST, cpi)).cast(frame.popObject())); - } - - private ResolvedJavaType resolveType(InterpreterFrame frame, int opcode, char cpi) { - ConstantPool constantPool = frame.getConstantPool(); - constantPool.loadReferencedType(cpi, opcode); - return constantPool.lookupType(cpi, opcode).resolve(frame.getMethod().getDeclaringClass()); - } - - private ResolvedJavaType resolveType(InterpreterFrame frame, Class javaClass) { - return metaAccessProvider.lookupJavaType(javaClass).resolve(frame.getMethod().getDeclaringClass()); - } - - private ResolvedJavaMethod resolveMethod(InterpreterFrame frame, int opcode, char cpi) { - ConstantPool constantPool = frame.getConstantPool(); - constantPool.loadReferencedType(cpi, opcode); - return (ResolvedJavaMethod) constantPool.lookupMethod(cpi, opcode); - } - - private ResolvedJavaField resolveField(InterpreterFrame frame, int opcode, char cpi) { - ConstantPool constantPool = frame.getConstantPool(); - constantPool.loadReferencedType(cpi, opcode); - return (ResolvedJavaField) constantPool.lookupField(cpi, opcode); - } - - private void instanceOf(InterpreterFrame frame, char cpi) { - frame.pushInt(resolveType(frame, Bytecodes.INSTANCEOF, cpi).isInstance(Constant.forObject(frame.popObject())) ? 1 : 0); - } - - private void pushCPConstant(InterpreterFrame frame, char cpi) { - ResolvedJavaMethod method = frame.getMethod(); - Object constant = method.getConstantPool().lookupConstant(cpi); - - if (constant instanceof Constant) { - Constant c = ((Constant) constant); - switch (c.getKind()) { - case Int: - frame.pushInt(c.asInt()); - break; - case Float: - frame.pushFloat(c.asFloat()); - break; - case Object: - frame.pushObject(c.asObject()); - break; - case Double: - frame.pushDouble(c.asDouble()); - break; - case Long: - frame.pushLong(c.asLong()); - break; - default: - assert false : "unspecified case"; - } - } else if (constant instanceof JavaType) { - frame.pushObject(mirror(((JavaType) constant).resolve(method.getDeclaringClass()))); - } else { - assert false : "unexpected case"; - } - } - - private void compareLong(InterpreterFrame frame) { - long y = frame.popLong(); - long x = frame.popLong(); - frame.pushInt((x < y) ? -1 : ((x == y) ? 0 : 1)); - } - - private void compareDoubleGreater(InterpreterFrame frame) { - double y = frame.popDouble(); - double x = frame.popDouble(); - frame.pushInt(x < y ? -1 : ((x == y) ? 0 : 1)); - } - - private void compareDoubleLess(InterpreterFrame frame) { - double y = frame.popDouble(); - double x = frame.popDouble(); - frame.pushInt(x > y ? 1 : ((x == y) ? 0 : -1)); - } - - private void compareFloatGreater(InterpreterFrame frame) { - float y = frame.popFloat(); - float x = frame.popFloat(); - frame.pushInt(x < y ? -1 : ((x == y) ? 0 : 1)); - } - - private void compareFloatLess(InterpreterFrame frame) { - float y = frame.popFloat(); - float x = frame.popFloat(); - frame.pushInt(x > y ? 1 : ((x == y) ? 0 : -1)); - } - - private Object nullCheck(Object value) { - if (value == null) { - throw new NullPointerException(); - } - return value; - } - - private InterpreterFrame invokeStatic(InterpreterFrame frame, char cpi) throws Throwable { - return invoke(frame, resolveMethod(frame, Bytecodes.INVOKESTATIC, cpi), null); - } - - private InterpreterFrame invokeInterface(InterpreterFrame frame, char cpi) throws Throwable { - return resolveAndInvoke(frame, resolveMethod(frame, Bytecodes.INVOKEINTERFACE, cpi)); - } - - private InterpreterFrame resolveAndInvoke(InterpreterFrame parent, ResolvedJavaMethod m) throws Throwable { - Object receiver = nullCheck(parent.peekReceiver(m)); - - ResolvedJavaMethod method = resolveType(parent, receiver.getClass()).resolveMethod(m); - - if (method == null) { - throw new AbstractMethodError(); - } - - return invoke(parent, method, receiver); - } - - private InterpreterFrame invokeVirtual(InterpreterFrame frame, char cpi) throws Throwable { - ResolvedJavaMethod m = resolveMethod(frame, Bytecodes.INVOKEVIRTUAL, cpi); - if (Modifier.isFinal(m.getModifiers())) { - return invoke(frame, m, nullCheck(frame.peekReceiver(m))); - } else { - return resolveAndInvoke(frame, m); - } - } - - private InterpreterFrame invokeSpecial(InterpreterFrame frame, char cpi) throws Throwable { - ResolvedJavaMethod m = resolveMethod(frame, Bytecodes.INVOKESPECIAL, cpi); - return invoke(frame, m, nullCheck(frame.peekReceiver(m))); - } - - private Object[] popArgumentsAsObject(InterpreterFrame frame, ResolvedJavaMethod method, boolean hasReceiver) { - Signature signature = method.getSignature(); - int argumentCount = method.getSignature().getParameterCount(hasReceiver); - Object[] parameters = new Object[argumentCount]; - - int lastSignatureIndex = hasReceiver ? 1 : 0; - for (int i = argumentCount - 1; i >= lastSignatureIndex; i--) { - ResolvedJavaType type = signature.getParameterType(i - lastSignatureIndex, method.getDeclaringClass()).resolve(method.getDeclaringClass()); - parameters[i] = popAsObject(frame, type.getKind()); - } - - if (hasReceiver) { - parameters[0] = frame.popObject(); - } - return parameters; - } - - private InterpreterFrame invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object receiver) throws Throwable { - if (caller.depth() >= maxStackFrames) { - throw new StackOverflowError("Maximum callstack of " + maxStackFrames + " exceeded."); - } - - if (Modifier.isNative(method.getModifiers())) { - return invokeNativeMethodViaVM(caller, method, receiver != null); - } else { - MethodRedirectionInfo redirectedMethod = methodDelegates.get(method); - if (redirectedMethod != null) { - return invokeRedirectedMethodViaVM(caller, method, redirectedMethod, receiver != null); - } else { - return invokeOptimized(caller, method, receiver != null); - } - } - } - - private InterpreterFrame invokeNativeMethodViaVM(InterpreterFrame caller, ResolvedJavaMethod method, boolean hasReceiver) throws Throwable { - assert !methodDelegates.containsKey(method) : "must not be redirected"; - if (TRACE) { - traceCall(caller, "Native " + method); - } - - // mark the current thread as high level and execute the native method - Object[] parameters = popArgumentsAsObject(caller, method, hasReceiver); - Object returnValue = runtimeInterface.invoke(method, parameters); - pushAsObject(caller, method.getSignature().getReturnKind(), returnValue); - - return null; - } - - private InterpreterFrame invokeRedirectedMethodViaVM(InterpreterFrame caller, ResolvedJavaMethod originalMethod, MethodRedirectionInfo redirectionInfo, boolean hasReceiver) throws Throwable { - assert methodDelegates.containsKey(originalMethod) : "must be redirected"; - if (TRACE) { - traceCall(caller, "Delegate " + originalMethod); - } - - // current thread is low level and we also execute the target method in the low-level - // interpreter - Object[] originalCalleeParameters = popArgumentsAsObject(caller, originalMethod, hasReceiver); - Object[] parameters = new Object[]{caller, originalMethod, originalCalleeParameters}; - Object returnValue = redirectionInfo.getTargetMethod().invoke(redirectionInfo.getReceiver(), parameters); - pushAsObject(caller, originalMethod.getSignature().getReturnKind(), returnValue); - - return null; - } - - private InterpreterFrame invokeOptimized(InterpreterFrame parent, ResolvedJavaMethod method, boolean hasReceiver) throws Throwable { - return parent.create(method, hasReceiver); - } - - private Object allocateMultiArray(InterpreterFrame frame, char cpi, int dimension) { - ResolvedJavaType type = getLastDimensionType(resolveType(frame, Bytecodes.MULTIANEWARRAY, cpi)); - - int[] dimensions = new int[dimension]; - for (int i = dimension - 1; i >= 0; i--) { - dimensions[i] = frame.popInt(); - } - return Array.newInstance(mirror(type), dimensions); - } - - private ResolvedJavaType getLastDimensionType(ResolvedJavaType type) { - ResolvedJavaType result = type; - while (result.isArray()) { - result = result.getComponentType(); - } - return result; - } - - private Object allocateArray(InterpreterFrame frame, char cpi) { - ResolvedJavaType type = resolveType(frame, Bytecodes.ANEWARRAY, cpi); - return Array.newInstance(runtimeInterface.getMirror(type), frame.popInt()); - } - - private Object allocateNativeArray(InterpreterFrame frame, byte cpi) { - // the constants for the cpi are loosely defined and no real cpi indices. - switch (cpi) { - case 4: - return new byte[frame.popInt()]; - case 8: - return new byte[frame.popInt()]; - case 5: - return new char[frame.popInt()]; - case 7: - return new double[frame.popInt()]; - case 6: - return new float[frame.popInt()]; - case 10: - return new int[frame.popInt()]; - case 11: - return new long[frame.popInt()]; - case 9: - return new short[frame.popInt()]; - default: - assert false : "unexpected case"; - return null; - } - } - - private Object allocateInstance(InterpreterFrame frame, char cpi) throws InstantiationException { - return runtimeInterface.newObject(resolveType(frame, Bytecodes.NEW, cpi)); - } - - private void iinc(InterpreterFrame frame, BytecodeStream bs) { - int index = frame.resolveLocalIndex(bs.readLocalIndex()); - frame.setInt(index, frame.getInt(index) + bs.readIncrement()); - } - - private void putStatic(InterpreterFrame frame, char cpi) { - putFieldStatic(frame, resolveField(frame, Bytecodes.PUTSTATIC, cpi)); - } - - private void putField(InterpreterFrame frame, char cpi) { - putFieldVirtual(frame, resolveField(frame, Bytecodes.PUTFIELD, cpi)); - } - - private void putFieldStatic(InterpreterFrame frame, ResolvedJavaField field) { - switch (field.getKind()) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - runtimeInterface.setFieldInt(frame.popInt(), null, field); - break; - case Double: - runtimeInterface.setFieldDouble(frame.popDouble(), null, field); - break; - case Float: - runtimeInterface.setFieldFloat(frame.popFloat(), null, field); - break; - case Long: - runtimeInterface.setFieldLong(frame.popLong(), null, field); - break; - case Object: - runtimeInterface.setFieldObject(frame.popObject(), null, field); - break; - default: - assert false : "unexpected case"; - } - } - - private void putFieldVirtual(InterpreterFrame frame, ResolvedJavaField field) { - switch (field.getKind()) { - case Boolean: - case Byte: - case Char: - case Short: - case Int: - runtimeInterface.setFieldInt(frame.popInt(), nullCheck(frame.popObject()), field); - break; - case Double: - runtimeInterface.setFieldDouble(frame.popDouble(), nullCheck(frame.popObject()), field); - break; - case Float: - runtimeInterface.setFieldFloat(frame.popFloat(), nullCheck(frame.popObject()), field); - break; - case Long: - runtimeInterface.setFieldLong(frame.popLong(), nullCheck(frame.popObject()), field); - break; - case Object: - runtimeInterface.setFieldObject(frame.popObject(), nullCheck(frame.popObject()), field); - break; - default: - assert false : "unexpected case"; - } - } - - private void getField(InterpreterFrame frame, Object base, int opcode, char cpi) { - ResolvedJavaField field = resolveField(frame, opcode, cpi); - switch (field.getKind()) { - case Boolean: - frame.pushInt(runtimeInterface.getFieldBoolean(base, field) ? 1 : 0); - break; - case Byte: - frame.pushInt(runtimeInterface.getFieldByte(base, field)); - break; - case Char: - frame.pushInt(runtimeInterface.getFieldChar(base, field)); - break; - case Short: - frame.pushInt(runtimeInterface.getFieldShort(base, field)); - break; - case Int: - frame.pushInt(runtimeInterface.getFieldInt(base, field)); - break; - case Double: - frame.pushDouble(runtimeInterface.getFieldDouble(base, field)); - break; - case Float: - frame.pushFloat(runtimeInterface.getFieldFloat(base, field)); - break; - case Long: - frame.pushLong(runtimeInterface.getFieldLong(base, field)); - break; - case Object: - frame.pushObject(runtimeInterface.getFieldObject(base, field)); - break; - default: - assert false : "unexpected case"; - } - } - - private int pushAsObject(InterpreterFrame frame, Kind typeKind, Object value) { - switch (typeKind) { - case Int: - frame.pushInt((int) value); - break; - case Long: - frame.pushLong((long) value); - return 2; - case Boolean: - frame.pushInt(((boolean) value) ? 1 : 0); - break; - case Byte: - frame.pushInt((byte) value); - break; - case Char: - frame.pushInt((char) value); - break; - case Double: - frame.pushDouble((double) value); - return 2; - case Float: - frame.pushFloat((float) value); - break; - case Short: - frame.pushInt((short) value); - break; - case Object: - frame.pushObject(value); - break; - case Void: - return 0; - default: - assert false : "case not specified"; - } - return 1; - } - - private Object popAsObject(InterpreterFrame frame, Kind typeKind) { - switch (typeKind) { - case Boolean: - return frame.popInt() == 1 ? true : false; - case Byte: - return (byte) frame.popInt(); - case Char: - return (char) frame.popInt(); - case Double: - return frame.popDouble(); - case Int: - return frame.popInt(); - case Float: - return frame.popFloat(); - case Long: - return frame.popLong(); - case Short: - return (short) frame.popInt(); - case Object: - return frame.popObject(); - case Void: - return null; - default: - assert false : "unexpected case"; - } - return null; - } - - private ResolvedJavaMethod resolveRootMethod() { - try { - return metaAccessProvider.lookupJavaMethod(BytecodeInterpreter.class.getDeclaredMethod("execute", Method.class, Object[].class)); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static Method findMethod(Class clazz, String name, Class... parameters) { - try { - return clazz.getDeclaredMethod(name, parameters); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private static StackTraceElement[] createStackTraceElements(InterpreterFrame frame, RuntimeInterpreterInterface runtimeInterface) { - InterpreterFrame tmp = frame; - List elements = new ArrayList<>(); - boolean first = false; // filter only first stack elements - while (tmp != null) { - if (first || !filterStackElement(tmp, runtimeInterface)) { - first = true; - elements.add(tmp.getMethod().asStackTraceElement(tmp.getBCI())); - } - tmp = tmp.getParentFrame(); - } - return elements.toArray(new StackTraceElement[elements.size()]); - } - - private static boolean filterStackElement(InterpreterFrame frame, RuntimeInterpreterInterface runtimeInterface) { - return Throwable.class.isAssignableFrom(runtimeInterface.getMirror(frame.getMethod().getDeclaringClass())); - } - - private ResolvedJavaField findThrowableField(InterpreterFrame frame, String name) { - ResolvedJavaType throwableType = resolveType(frame, Throwable.class); - ResolvedJavaField[] fields = throwableType.getInstanceFields(false); - for (int i = 0; i < fields.length; i++) { - if (fields[i].getName().equals(name)) { - return fields[i]; - } - } - assert false; - return null; - } - - private class MethodRedirectionInfo { - - private InterpreterCallable receiver; - private Method method; - - public MethodRedirectionInfo(InterpreterCallable instance) { - this.receiver = instance; - this.method = resolveMethod(instance); - } - - public InterpreterCallable getReceiver() { - return receiver; - } - - public Method getTargetMethod() { - return method; - } - - private Method resolveMethod(InterpreterCallable instance) { - try { - return instance.getClass().getMethod(InterpreterCallable.INTERPRETER_CALLABLE_INVOKE_NAME, InterpreterCallable.INTERPRETER_CALLABLE_INVOKE_SIGNATURE); - } catch (NoSuchMethodException e) { - throw new InterpreterException(e); - } catch (SecurityException e) { - throw new InterpreterException(e); - } - } - } -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/Frame.java --- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/Frame.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,134 +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.interpreter; - -import java.lang.reflect.*; - -import sun.misc.*; - -public class Frame { - - public static final Object[] EMPTY_ARRAY = new Object[0]; - public static final int PARENT_FRAME_SLOT = 0; - public static final int MIN_FRAME_SIZE = 1; - private static final Unsafe unsafe = getUnsafe(); - - protected final Object[] locals; - protected final long[] primitiveLocals; - - public Frame(int numLocals, Frame parent) { - assert numLocals >= MIN_FRAME_SIZE; - this.locals = new Object[numLocals]; - this.locals[PARENT_FRAME_SLOT] = parent; - this.primitiveLocals = new long[numLocals]; - } - - public Frame(int numLocals) { - this(numLocals, null); - } - - public Object getObject(int index) { - return locals[index]; - } - - public void setObject(int index, Object value) { - locals[index] = value; - } - - public float getFloat(int index) { - return unsafe.getFloat(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET); - } - - public void setFloat(int index, float value) { - unsafe.putFloat(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET, value); - } - - public long getLong(int index) { - return unsafe.getLong(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET); - } - - public void setLong(int index, long value) { - unsafe.putLong(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET, value); - } - - public int getInt(int index) { - return unsafe.getInt(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET); - } - - public void setInt(int index, int value) { - unsafe.putInt(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET, value); - } - - public double getDouble(int index) { - return unsafe.getDouble(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET); - } - - public void setDouble(int index, double value) { - unsafe.putDouble(primitiveLocals, (long) index * Unsafe.ARRAY_LONG_INDEX_SCALE + Unsafe.ARRAY_LONG_BASE_OFFSET, value); - } - - public static Frame getParentFrame(Frame frame, int level) { - assert level >= 0; - if (level == 0) { - return frame; - } else { - return getParentFrame((Frame) frame.getObject(PARENT_FRAME_SLOT), level - 1); - } - } - - public static Frame getTopFrame(Frame frame) { - Frame parentFrame = (Frame) frame.getObject(PARENT_FRAME_SLOT); - if (parentFrame == null) { - return frame; - } else { - return getTopFrame(parentFrame); - } - } - - public static Object[] getArguments(Frame frame, int argOffset) { - return (Object[]) frame.getObject(argOffset); - } - - public int size() { - return locals.length; - } - - @SuppressWarnings("unused") - private boolean indexExists(int index) { - return index >= 0 && index < locals.length; - } - - private static Unsafe getUnsafe() { - try { - return Unsafe.getUnsafe(); - } catch (SecurityException e) { - } - try { - Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe"); - theUnsafeInstance.setAccessible(true); - return (Unsafe) theUnsafeInstance.get(Unsafe.class); - } catch (Exception e) { - throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e); - } - } -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterCallable.java --- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterCallable.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,35 +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.interpreter; - -import com.oracle.graal.api.meta.*; - -public interface InterpreterCallable { - - // static final fields - String INTERPRETER_CALLABLE_INVOKE_NAME = "invoke"; - Class[] INTERPRETER_CALLABLE_INVOKE_SIGNATURE = {InterpreterFrame.class, ResolvedJavaMethod.class, Object[].class}; - - // methods - Object invoke(InterpreterFrame caller, ResolvedJavaMethod method, Object[] arguments) throws Throwable; -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterException.java --- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterException.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +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.interpreter; - -/** - * Thrown if executed byte code caused an error in {@link BytecodeInterpreter}. The actual execution - * exception is accessible using {@link #getCause()} or {@link #getExecutionThrowable()}. - */ -public class InterpreterException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public InterpreterException(Throwable cause) { - super(cause); - } - - public Throwable getExecutionThrowable() { - return getCause(); - } - -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterFrame.java --- a/graal/com.oracle.graal.interpreter/src/com/oracle/graal/interpreter/InterpreterFrame.java Mon Feb 04 20:18:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,353 +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.interpreter; - -import java.util.*; - -import com.oracle.graal.api.meta.*; - -public class InterpreterFrame extends Frame { - - public static final int BASE_LENGTH = 3; - - private static final int METHOD_FRAME_SLOT = 1; - private static final int BCI_FRAME_SLOT = 2; - - private static final int DOUBLE = 2; - private static final int SINGLE = 1; - - /** Pointer to the top-most stack frame element. */ - private int depth; - private int tos; - - public InterpreterFrame(ResolvedJavaMethod method, int additionalStackSpace) { - this(method, null, additionalStackSpace, 0); - } - - private InterpreterFrame(ResolvedJavaMethod method, InterpreterFrame parent, int additionalStackSpace, int depth) { - super(method.getMaxLocals() + method.getMaxStackSize() + BASE_LENGTH + additionalStackSpace, parent); - setMethod(method); - setBCI(0); - this.depth = depth; - this.tos = BASE_LENGTH; - } - - public InterpreterFrame create(ResolvedJavaMethod method, boolean hasReceiver) { - InterpreterFrame frame = new InterpreterFrame(method, this, 0, this.depth + 1); - int length = method.getSignature().getParameterSlots(hasReceiver); - - frame.pushVoid(method.getMaxLocals()); - if (length > 0) { - copyArguments(frame, length); - popVoid(length); - } - - return frame; - } - - public int resolveLocalIndex(int index) { - return BASE_LENGTH + index; - } - - public int depth() { - return depth; - } - - private int stackTos() { - return BASE_LENGTH + getMethod().getMaxLocals(); - } - - private void copyArguments(InterpreterFrame dest, int length) { - System.arraycopy(locals, tosSingle(length - 1), dest.locals, BASE_LENGTH, length); - System.arraycopy(primitiveLocals, tosSingle(length - 1), dest.primitiveLocals, BASE_LENGTH, length); - } - - public Object peekReceiver(ResolvedJavaMethod method) { - return getObject(tosSingle(method.getSignature().getParameterSlots(false))); - } - - public void pushBoth(Object oValue, int intValue) { - incrementTos(SINGLE); - setObject(tosSingle(0), oValue); - setInt(tosSingle(0), intValue); - } - - public void pushBoth(Object oValue, long longValue) { - incrementTos(SINGLE); - setObject(tosSingle(0), oValue); - setLong(tosSingle(0), longValue); - } - - public void pushObject(Object value) { - incrementTos(SINGLE); - setObject(tosSingle(0), value); - } - - public void pushInt(int value) { - incrementTos(SINGLE); - setInt(tosSingle(0), value); - } - - public void pushDouble(double value) { - incrementTos(DOUBLE); - setDouble(tosDouble(0), value); - } - - public void pushFloat(float value) { - incrementTos(SINGLE); - setFloat(tosSingle(0), value); - } - - public void pushLong(long value) { - incrementTos(DOUBLE); - setLong(tosDouble(0), value); - } - - public int popInt() { - int value = getInt(tosSingle(0)); - decrementTos(SINGLE); - return value; - } - - public double popDouble() { - double value = getDouble(tosDouble(0)); - decrementTos(DOUBLE); - return value; - } - - public float popFloat() { - float value = getFloat(tosSingle(0)); - decrementTos(SINGLE); - return value; - } - - public long popLong() { - long value = getLong(tosDouble(0)); - decrementTos(DOUBLE); - return value; - } - - public Object popObject() { - Object value = getObject(tosSingle(0)); - decrementTos(SINGLE); - return value; - } - - public void swapSingle() { - int tmpInt = getInt(tosSingle(1)); - Object tmpObject = getObject(tosSingle(1)); - - setInt(tosSingle(1), getInt(tosSingle(0))); - setObject(tosSingle(1), getObject(tosSingle(0))); - - setInt(tosSingle(0), tmpInt); - setObject(tosSingle(0), tmpObject); - } - - public void dupx1() { - long tosLong = getLong(tosSingle(0)); - Object tosObject = getObject(tosSingle(0)); - - swapSingle(); - - pushBoth(tosObject, tosLong); - } - - public void dup2x1() { - long tosLong2 = getLong(tosSingle(2)); - Object tosObject2 = getObject(tosSingle(2)); - long tosLong1 = getLong(tosSingle(1)); - Object tosObject1 = getObject(tosSingle(1)); - long tosLong0 = getLong(tosSingle(0)); - Object tosObject0 = getObject(tosSingle(0)); - - popVoid(3); - - pushBoth(tosObject1, tosLong1); - pushBoth(tosObject0, tosLong0); - - pushBoth(tosObject2, tosLong2); - - pushBoth(tosObject1, tosLong1); - pushBoth(tosObject0, tosLong0); - } - - public void dup2x2() { - long tosLong3 = getLong(tosSingle(3)); - Object tosObject3 = getObject(tosSingle(3)); - long tosLong2 = getLong(tosSingle(2)); - Object tosObject2 = getObject(tosSingle(2)); - long tosLong1 = getLong(tosSingle(1)); - Object tosObject1 = getObject(tosSingle(1)); - long tosLong0 = getLong(tosSingle(0)); - Object tosObject0 = getObject(tosSingle(0)); - - popVoid(4); - - pushBoth(tosObject1, tosLong1); - pushBoth(tosObject0, tosLong0); - - pushBoth(tosObject3, tosLong3); - pushBoth(tosObject2, tosLong2); - - pushBoth(tosObject1, tosLong1); - pushBoth(tosObject0, tosLong0); - } - - public void dupx2() { - long tosLong2 = getLong(tosSingle(2)); - Object tosObject2 = getObject(tosSingle(2)); - long tosLong1 = getLong(tosSingle(1)); - Object tosObject1 = getObject(tosSingle(1)); - long tosLong0 = getLong(tosSingle(0)); - Object tosObject0 = getObject(tosSingle(0)); - - popVoid(3); - - pushBoth(tosObject0, tosLong0); - pushBoth(tosObject2, tosLong2); - pushBoth(tosObject1, tosLong1); - pushBoth(tosObject0, tosLong0); - } - - public void dup(int length) { - assert length > 0; - for (int i = 0; i < length; i++) { - long valueN1 = getLong(tosSingle(length - i - 1)); - Object valueO1 = getObject(tosSingle(length - i - 1)); - - pushVoid(1); - - setLong(tosSingle(0), valueN1); - setObject(tosSingle(0), valueO1); - } - } - - private void incrementTos(int size) { - tos += size; - } - - private void decrementTos(int size) { - assert tos - size >= stackTos(); - tos -= size; - } - - private int tosDouble(int offset) { - assert offset >= 0; - return tos - DOUBLE - (offset * DOUBLE); - } - - private int tosSingle(int offset) { - assert offset >= 0; - return tos - SINGLE - offset; - } - - public int getStackTop() { - return tos; - } - - public void pushVoid(int count) { - incrementTos(count * SINGLE); - } - - public void popVoid(int count) { - decrementTos(count * SINGLE); - } - - public ConstantPool getConstantPool() { - return getMethod().getConstantPool(); - } - - private void setMethod(ResolvedJavaMethod method) { - setObject(METHOD_FRAME_SLOT, method); - } - - public ResolvedJavaMethod getMethod() { - return (ResolvedJavaMethod) getObject(METHOD_FRAME_SLOT); - } - - public void setBCI(int bci) { - setInt(BCI_FRAME_SLOT, bci); - } - - public int getBCI() { - return getInt(BCI_FRAME_SLOT); - } - - public void pushTo(InterpreterFrame childFrame, int argumentSlots) { - System.arraycopy(locals, tos - argumentSlots, childFrame.locals, InterpreterFrame.MIN_FRAME_SIZE, argumentSlots); - - System.arraycopy(primitiveLocals, tos - argumentSlots, childFrame.primitiveLocals, InterpreterFrame.MIN_FRAME_SIZE, argumentSlots); - popVoid(argumentSlots); - } - - public InterpreterFrame getParentFrame() { - return (InterpreterFrame) getObject(PARENT_FRAME_SLOT); - } - - public void dispose() { - // Clear out references in locals array. - Arrays.fill(locals, null); - } - - @Override - public String toString() { - ResolvedJavaMethod method = getMethod(); - StringBuilder b = new StringBuilder(getMethod().asStackTraceElement(getBCI()).toString()); - for (int i = 0; i < tos; i++) { - Object object = getObject(tosSingle(i)); - long primitive = getLong(tosSingle(i)); - - String objectString = null; - if (object != null) { - objectString = object.getClass().getSimpleName() + "@" + Integer.toHexString(object.hashCode()); - } - String primitiveString = "0x" + Long.toHexString(primitive).toUpperCase(); - String typeString; - - int index = tosSingle(i); - if (index == METHOD_FRAME_SLOT) { - typeString = "method"; - } else if (index == BCI_FRAME_SLOT) { - typeString = "bci"; - } else if (index == PARENT_FRAME_SLOT) { - typeString = "parent"; - } else if (index < BASE_LENGTH + method.getMaxLocals()) { - typeString = "var " + (index - BASE_LENGTH); - } else { - typeString = "local"; - } - b.append(String.format("%n [%d] %7s Primitive: %10s Object: %s", index, typeString, primitiveString, objectString)); - } - if (getParentFrame() != null) { - b.append("\n").append(getParentFrame().toString()); - } - return b.toString(); - } - - public void popStack() { - // TODO(chumer): prevent popping local variables. - popVoid(tos - stackTos()); - } - -} diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/IfNode.java Mon Feb 04 20:23:57 2013 +0100 @@ -323,6 +323,7 @@ } } assert !ends.hasNext(); + assert falseEnds.size() + trueEnds.size() == xs.length; connectEnds(falseEnds, phiValues, oldFalseSuccessor, merge, tool); connectEnds(trueEnds, phiValues, oldTrueSuccessor, merge, tool); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/MethodCallTargetNode.java Mon Feb 04 20:23:57 2013 +0100 @@ -131,10 +131,6 @@ return this; } - public JavaType returnType() { - return returnType; - } - @Override public Stamp returnStamp() { Kind returnKind = targetMethod.getSignature().getReturnKind(); @@ -145,6 +141,10 @@ } } + public JavaType returnType() { + return returnType; + } + @Override public String targetName() { if (targetMethod() == null) { diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/CanonicalizerPhase.java Mon Feb 04 20:23:57 2013 +0100 @@ -123,6 +123,7 @@ for (Node n : workList) { processNode(n, graph); + Debug.dump(graph, "After processing %s", n); } graph.stopTrackingInputChange(); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ComputeProbabilityPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ComputeProbabilityPhase.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/ComputeProbabilityPhase.java Mon Feb 04 20:23:57 2013 +0100 @@ -60,63 +60,9 @@ computeLoopFactors(); Debug.dump(graph, "After computeLoopFactors"); new PropagateLoopFrequency(graph.start()).apply(); - - if (GraalOptions.LoopFrequencyPropagationPolicy < 0) { - ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false); - BitSet visitedBlocks = new BitSet(cfg.getBlocks().length); - for (Loop loop : cfg.getLoops()) { - if (loop.parent == null) { - correctLoopFrequencies(loop, 1, visitedBlocks); - } - } - } - new ComputeInliningRelevanceIterator(graph).apply(); } - private void correctLoopFrequencies(Loop loop, double parentFrequency, BitSet visitedBlocks) { - LoopBeginNode loopBegin = ((LoopBeginNode) loop.header.getBeginNode()); - double frequency = parentFrequency * loopBegin.loopFrequency(); - if (frequency < 1) { - frequency = 1; - } - for (Loop child : loop.children) { - correctLoopFrequencies(child, frequency, visitedBlocks); - } - - double factor = getCorrectionFactor(loopBegin.probability(), frequency); - for (Block block : loop.blocks) { - int blockId = block.getId(); - if (!visitedBlocks.get(blockId)) { - visitedBlocks.set(blockId); - - FixedNode node = block.getBeginNode(); - while (node != block.getEndNode()) { - node.setProbability(node.probability() * factor); - node = ((FixedWithNextNode) node).next(); - } - node.setProbability(node.probability() * factor); - } - } - } - - private static double getCorrectionFactor(double probability, double frequency) { - switch (GraalOptions.LoopFrequencyPropagationPolicy) { - case -1: - return 1 / frequency; - case -2: - return (1 / frequency) * (Math.log(Math.E + frequency) - 1); - case -3: - double originalProbability = probability / frequency; - assert isRelativeProbability(originalProbability); - return (1 / frequency) * Math.max(1, Math.pow(originalProbability, 1.5) * Math.log10(frequency)); - case -4: - return 1 / probability; - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - private void computeLoopFactors() { for (LoopInfo info : loopInfos) { double frequency = info.loopFrequency(); @@ -330,124 +276,184 @@ private class PropagateLoopFrequency extends PostOrderNodeIterator { - private final FrequencyPropagationPolicy policy; - public PropagateLoopFrequency(FixedNode start) { super(start, new LoopCount(1d)); - this.policy = createFrequencyPropagationPolicy(); } @Override protected void node(FixedNode node) { - node.setProbability(policy.compute(node.probability(), state.count)); + node.setProbability(node.probability() * state.count); } } - private static FrequencyPropagationPolicy createFrequencyPropagationPolicy() { - switch (GraalOptions.LoopFrequencyPropagationPolicy) { - case -4: - case -3: - case -2: - case -1: - case 0: - return new FullFrequencyPropagation(); - case 1: - return new NoFrequencyPropagation(); - default: - throw GraalInternalError.shouldNotReachHere(); - } - } - - private interface FrequencyPropagationPolicy { - - double compute(double probability, double frequency); - } - - private static class FullFrequencyPropagation implements FrequencyPropagationPolicy { - - @Override - public double compute(double probability, double frequency) { - return probability * frequency; - } - } - - private static class NoFrequencyPropagation implements FrequencyPropagationPolicy { - - @Override - public double compute(double probability, double frequency) { - return probability; - } - } - private static class ComputeInliningRelevanceIterator extends ScopedPostOrderNodeIterator { - private final HashMap lowestPathProbabilities; + private final HashMap scopes; private double currentProbability; + private double parentRelevance; public ComputeInliningRelevanceIterator(StructuredGraph graph) { super(graph); - this.lowestPathProbabilities = computeLowestPathProbabilities(graph); + this.scopes = computeLowestPathProbabilities(computeScopeInformation(graph)); } @Override protected void initializeScope() { - currentProbability = lowestPathProbabilities.get(currentScope); + Scope scope = scopes.get(currentScopeStart); + parentRelevance = getParentScopeRelevance(scope); + currentProbability = scope.minPathProbability; + } + + private static double getParentScopeRelevance(Scope scope) { + if (scope.start instanceof LoopBeginNode) { + assert scope.parent != null; + double parentProbability = 0; + for (EndNode end : ((LoopBeginNode) scope.start).forwardEnds()) { + parentProbability += end.probability(); + } + return parentProbability / scope.parent.minPathProbability; + } else { + assert scope.parent == null; + return 1.0; + } } @Override protected void invoke(Invoke invoke) { assert !Double.isNaN(invoke.probability()); - invoke.setInliningRelevance(invoke.probability() / currentProbability); + invoke.setInliningRelevance((invoke.probability() / currentProbability) * Math.min(1.0, parentRelevance)); + assert !Double.isNaN(invoke.inliningRelevance()); } - private HashMap computeLowestPathProbabilities(StructuredGraph graph) { - HashMap result = new HashMap<>(); - Deque scopes = getScopes(graph); + private static Scope[] computeScopeInformation(StructuredGraph graph) { + ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false); + + Loop[] loops = cfg.getLoops(); + HashMap processedScopes = new HashMap<>(); + Scope[] scopes = new Scope[loops.length + 1]; + Scope methodScope = new Scope(graph.start(), null); + processedScopes.put(null, methodScope); + + scopes[0] = methodScope; + for (int i = 0; i < loops.length; i++) { + scopes[i + 1] = createScope(loops[i], processedScopes); + } + + return scopes; + } - while (!scopes.isEmpty()) { - FixedNode scopeBegin = scopes.pop(); - double probability = computeLowestPathProbability(scopeBegin); - result.put(scopeBegin, probability); + private static Scope createScope(Loop loop, HashMap processedLoops) { + Scope parent = processedLoops.get(loop.parent); + if (parent == null) { + parent = createScope(loop, processedLoops); + } + Scope result = new Scope(loop.loopBegin(), parent); + processedLoops.put(loop, result); + return result; + } + + private static HashMap computeLowestPathProbabilities(Scope[] scopes) { + HashMap result = new HashMap<>(); + + for (Scope scope : scopes) { + double lowestPathProbability = computeLowestPathProbability(scope); + scope.minPathProbability = Math.max(EPSILON, lowestPathProbability); + result.put(scope.start, scope); } return result; } - private static double computeLowestPathProbability(FixedNode scopeStart) { + private static double computeLowestPathProbability(Scope scope) { + FixedNode scopeStart = scope.start; + ArrayList pathBeginNodes = new ArrayList<>(); + pathBeginNodes.add(scopeStart); double minPathProbability = scopeStart.probability(); - Node current = scopeStart; + boolean isLoopScope = scopeStart instanceof LoopBeginNode; - while (current != null) { - if (current.successors().count() > 1) { - assert current instanceof ControlSplitNode; - ControlSplitNode controlSplit = (ControlSplitNode) current; - current = getMaxProbabilitySux(controlSplit); - if (((FixedNode) current).probability() < minPathProbability) { - minPathProbability = ((FixedNode) current).probability(); + do { + Node current = pathBeginNodes.remove(pathBeginNodes.size() - 1); + do { + if (isLoopScope && current instanceof LoopExitNode && ((LoopBeginNode) scopeStart).loopExits().contains((LoopExitNode) current)) { + return minPathProbability; + } else if (current instanceof LoopBeginNode && current != scopeStart) { + current = getMaxProbabilityLoopExit((LoopBeginNode) current, pathBeginNodes); + minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability); + } else if (current instanceof ControlSplitNode) { + current = getMaxProbabilitySux((ControlSplitNode) current, pathBeginNodes); + minPathProbability = getMinPathProbability((FixedNode) current, minPathProbability); + } else { + assert current.successors().count() <= 1; + current = current.successors().first(); } - } else { - current = current.successors().first(); - } - } + } while (current != null); + } while (!pathBeginNodes.isEmpty()); return minPathProbability; } - private static Node getMaxProbabilitySux(ControlSplitNode controlSplit) { + private static double getMinPathProbability(FixedNode current, double minPathProbability) { + if (current != null && current.probability() < minPathProbability) { + return current.probability(); + } + return minPathProbability; + } + + private static Node getMaxProbabilitySux(ControlSplitNode controlSplit, ArrayList pathBeginNodes) { Node maxSux = null; double maxProbability = 0.0; + int pathBeginCount = pathBeginNodes.size(); - // TODO: process recursively if we have multiple successors with same probability for (Node sux : controlSplit.successors()) { double probability = controlSplit.probability((BeginNode) sux); if (probability > maxProbability) { maxProbability = probability; maxSux = sux; + truncate(pathBeginNodes, pathBeginCount); + } else if (probability == maxProbability) { + pathBeginNodes.add((FixedNode) sux); } } return maxSux; } + + private static Node getMaxProbabilityLoopExit(LoopBeginNode loopBegin, ArrayList pathBeginNodes) { + Node maxSux = null; + double maxProbability = 0.0; + int pathBeginCount = pathBeginNodes.size(); + + for (LoopExitNode sux : loopBegin.loopExits()) { + double probability = sux.probability(); + if (probability > maxProbability) { + maxProbability = probability; + maxSux = sux; + truncate(pathBeginNodes, pathBeginCount); + } else if (probability == maxProbability) { + pathBeginNodes.add(sux); + } + } + + return maxSux; + } + + public static void truncate(ArrayList pathBeginNodes, int pathBeginCount) { + for (int i = pathBeginNodes.size() - pathBeginCount; i > 0; i--) { + pathBeginNodes.remove(pathBeginNodes.size() - 1); + } + } + } + + private static class Scope { + + public final FixedNode start; + public final Scope parent; + public double minPathProbability; + + public Scope(FixedNode start, Scope parent) { + this.start = start; + this.parent = parent; + } } } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningPhase.java Mon Feb 04 20:23:57 2013 +0100 @@ -32,9 +32,11 @@ import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.phases.*; -import com.oracle.graal.phases.PhasePlan.*; +import com.oracle.graal.phases.PhasePlan.PhasePosition; import com.oracle.graal.phases.common.CanonicalizerPhase.CustomCanonicalizer; -import com.oracle.graal.phases.common.InliningUtil.*; +import com.oracle.graal.phases.common.InliningUtil.InlineInfo; +import com.oracle.graal.phases.common.InliningUtil.InliningCallback; +import com.oracle.graal.phases.common.InliningUtil.InliningPolicy; public class InliningPhase extends Phase implements InliningCallback { @@ -52,6 +54,7 @@ private final Assumptions assumptions; private final GraphCache cache; private final InliningPolicy inliningPolicy; + private final OptimisticOptimizations optimisticOpts; private CustomCanonicalizer customCanonicalizer; // Metrics @@ -62,20 +65,22 @@ public InliningPhase(TargetDescription target, GraalCodeCacheProvider runtime, Collection hints, Assumptions assumptions, GraphCache cache, PhasePlan plan, OptimisticOptimizations optimisticOpts) { - this(target, runtime, assumptions, cache, plan, createInliningPolicy(assumptions, optimisticOpts, hints)); + this(target, runtime, assumptions, cache, plan, createInliningPolicy(runtime, assumptions, optimisticOpts, hints), optimisticOpts); } public void setCustomCanonicalizer(CustomCanonicalizer customCanonicalizer) { this.customCanonicalizer = customCanonicalizer; } - public InliningPhase(TargetDescription target, GraalCodeCacheProvider runtime, Assumptions assumptions, GraphCache cache, PhasePlan plan, InliningPolicy inliningPolicy) { + public InliningPhase(TargetDescription target, GraalCodeCacheProvider runtime, Assumptions assumptions, GraphCache cache, PhasePlan plan, InliningPolicy inliningPolicy, + OptimisticOptimizations optimisticOpts) { this.target = target; this.runtime = runtime; this.assumptions = assumptions; this.cache = cache; this.plan = plan; this.inliningPolicy = inliningPolicy; + this.optimisticOpts = optimisticOpts; } @Override @@ -96,14 +101,12 @@ candidate.inline(graph, runtime, this, assumptions); Debug.dump(graph, "after %s", candidate); Iterable newNodes = graph.getNewNodes(mark); + inliningPolicy.scanInvokes(newNodes); if (GraalOptions.OptCanonicalizer) { new CanonicalizerPhase(target, runtime, assumptions, invokeUsages, mark, customCanonicalizer).apply(graph); } metricInliningPerformed.increment(); - - inliningPolicy.scanInvokes(newNodes); } catch (BailoutException bailout) { - // TODO determine if we should really bail out of the whole compilation. throw bailout; } catch (AssertionError e) { throw new GraalInternalError(e).addContext(candidate.toString()); @@ -112,6 +115,8 @@ } catch (GraalInternalError e) { throw e.addContext(candidate.toString()); } + } else if (optimisticOpts.devirtualizeInvokes()) { + candidate.tryToDevirtualizeInvoke(graph, runtime, assumptions); } } } @@ -153,171 +158,174 @@ boolean isWorthInlining(InlineInfo info); } - private abstract static class AbstractInliningDecision implements InliningDecision { - - protected static boolean decideSizeBasedInlining(InlineInfo info, double maxSize) { - assert !Double.isNaN(info.weight()) && !Double.isNaN(maxSize); - boolean success = info.weight() <= maxSize; - if (GraalOptions.Debug) { - String formatterString = success ? "(size %f <= %f)" : "(too large %f > %f)"; - InliningUtil.logInliningDecision(info, success, formatterString, info.weight(), maxSize); - } - return success; - } + private static class GreedySizeBasedInliningDecision implements InliningDecision { - protected static boolean checkCompiledCodeSize(InlineInfo info) { - if (GraalOptions.SmallCompiledCodeSize >= 0 && info.compiledCodeSize() > GraalOptions.SmallCompiledCodeSize) { - InliningUtil.logNotInlinedMethod(info, "(CompiledCodeSize %d > %d)", info.compiledCodeSize(), GraalOptions.SmallCompiledCodeSize); - return false; - } - return true; - } - - protected static double getRelevance(Invoke invoke) { - if (GraalOptions.UseRelevanceBasedInlining) { - return invoke.inliningRelevance(); - } else { - return invoke.probability(); - } - } - } - - private static class C1StaticSizeBasedInliningDecision extends AbstractInliningDecision { - - @Override - public boolean isWorthInlining(InlineInfo info) { - double maxSize = Math.max(GraalOptions.MaximumTrivialSize, Math.pow(GraalOptions.NestedInliningSizeRatio, info.level()) * GraalOptions.MaximumInlineSize); - return decideSizeBasedInlining(info, maxSize); - } - } + private final GraalCodeCacheProvider runtime; + private final Collection hints; - private static class MinimumCodeSizeBasedInliningDecision extends AbstractInliningDecision { - - @Override - public boolean isWorthInlining(InlineInfo info) { - assert GraalOptions.ProbabilityAnalysis; - if (!checkCompiledCodeSize(info)) { - return false; - } - - double inlineWeight = Math.min(GraalOptions.RatioCapForInlining, getRelevance(info.invoke())); - double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level()) * GraalOptions.MaximumInlineSize * inlineWeight; - maxSize = Math.max(GraalOptions.MaximumTrivialSize, maxSize); - - return decideSizeBasedInlining(info, maxSize); + public GreedySizeBasedInliningDecision(GraalCodeCacheProvider runtime, Collection hints) { + this.runtime = runtime; + this.hints = hints; } - } - - private static class DynamicSizeBasedInliningDecision extends AbstractInliningDecision { - - @Override - public boolean isWorthInlining(InlineInfo info) { - assert GraalOptions.ProbabilityAnalysis; - if (!checkCompiledCodeSize(info)) { - return false; - } - - double relevance = getRelevance(info.invoke()); - double inlineBoost = Math.min(GraalOptions.RatioCapForInlining, relevance) + Math.log10(Math.max(1, relevance - GraalOptions.RatioCapForInlining + 1)); - double maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level()) * GraalOptions.MaximumInlineSize; - maxSize = maxSize + maxSize * inlineBoost; - maxSize = Math.min(GraalOptions.MaximumGreedyInlineSize, Math.max(GraalOptions.MaximumTrivialSize, maxSize)); - - return decideSizeBasedInlining(info, maxSize); - } - } - - private static class GreedySizeBasedInliningDecision extends AbstractInliningDecision { @Override public boolean isWorthInlining(InlineInfo info) { assert GraalOptions.ProbabilityAnalysis; - if (!checkCompiledCodeSize(info)) { - return false; + /* + * TODO (chaeubl): invoked methods that are on important paths but not yet compiled -> + * will be compiled anyways and it is likely that we are the only caller... might be + * useful to inline those methods but increases bootstrap time (maybe those methods are + * also getting queued in the compilation queue concurrently) + */ + + if (GraalOptions.AlwaysInlineIntrinsics && onlyIntrinsics(info)) { + return InliningUtil.logInlinedMethod(info, "intrinsic"); } - double maxSize = GraalOptions.MaximumGreedyInlineSize; - if (GraalOptions.InliningBonusPerTransferredValue != 0) { - Signature signature = info.invoke().methodCallTarget().targetMethod().getSignature(); - int transferredValues = signature.getParameterCount(!Modifier.isStatic(info.invoke().methodCallTarget().targetMethod().getModifiers())); - if (signature.getReturnKind() != Kind.Void) { - transferredValues++; + int bytecodeSize = bytecodeCodeSize(info); + int complexity = compilationComplexity(info); + int compiledCodeSize = compiledCodeSize(info); + double relevance = info.invoke().inliningRelevance(); + + /* + * as long as the compiled code size is small enough (or the method was not yet + * compiled), we can do a pretty general inlining that suits most situations + */ + if (compiledCodeSize < GraalOptions.SmallCompiledCodeSize) { + if (isTrivialInlining(bytecodeSize, complexity, compiledCodeSize)) { + return InliningUtil.logInlinedMethod(info, "trivial (bytecodes=%d, complexity=%d, codeSize=%d)", bytecodeSize, complexity, compiledCodeSize); } - maxSize += transferredValues * GraalOptions.InliningBonusPerTransferredValue; + + if (canInlineRelevanceBased(relevance, bytecodeSize, complexity, compiledCodeSize)) { + return InliningUtil.logInlinedMethod(info, "relevance-based (relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d)", relevance, bytecodeSize, complexity, compiledCodeSize); + } } - double inlineRatio = Math.min(GraalOptions.RatioCapForInlining, getRelevance(info.invoke())); - maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level()) * maxSize * inlineRatio; - maxSize = Math.max(maxSize, GraalOptions.MaximumTrivialSize); + /* + * the normal inlining did not fit this invoke, so check if we have any reason why we + * should still do the inlining + */ + double probability = info.invoke().probability(); + int transferredValues = numberOfTransferredValues(info); + int invokeUsages = countInvokeUsages(info); + int moreSpecificArguments = countMoreSpecificArgumentInfo(info); + int level = info.level(); + boolean preferredInvoke = hints != null && hints.contains(info.invoke()); - return decideSizeBasedInlining(info, maxSize); + // TODO (chaeubl): compute metric that is used to check if this method should be inlined + + return InliningUtil.logNotInlinedMethod(info, + "(relevance=%f, bytecodes=%d, complexity=%d, codeSize=%d, probability=%f, transferredValues=%d, invokeUsages=%d, moreSpecificArguments=%d, level=%d, preferred=%b)", + relevance, bytecodeSize, complexity, compiledCodeSize, probability, transferredValues, invokeUsages, moreSpecificArguments, level, preferredInvoke); } - } + + private static boolean isTrivialInlining(int bytecodeSize, int complexity, int compiledCodeSize) { + return bytecodeSize < GraalOptions.TrivialBytecodeSize || complexity < GraalOptions.TrivialComplexity || compiledCodeSize > 0 && compiledCodeSize < GraalOptions.TrivialCompiledCodeSize; + } - private static class GreedyMachineCodeInliningDecision extends AbstractInliningDecision { + private static boolean canInlineRelevanceBased(double relevance, int bytecodeSize, int complexity, int compiledCodeSize) { + return bytecodeSize < computeMaximumSize(relevance, GraalOptions.NormalBytecodeSize) || complexity < computeMaximumSize(relevance, GraalOptions.NormalComplexity) || compiledCodeSize > 0 && + compiledCodeSize < computeMaximumSize(relevance, GraalOptions.NormalCompiledCodeSize); + } - @Override - public boolean isWorthInlining(InlineInfo info) { - assert GraalOptions.ProbabilityAnalysis; + private static double computeMaximumSize(double relevance, int configuredMaximum) { + double inlineRatio = Math.min(GraalOptions.RelevanceCapForInlining, relevance); + return configuredMaximum * inlineRatio; + } + + private static int numberOfTransferredValues(InlineInfo info) { + Signature signature = info.invoke().methodCallTarget().targetMethod().getSignature(); + int transferredValues = signature.getParameterCount(!Modifier.isStatic(info.invoke().methodCallTarget().targetMethod().getModifiers())); + if (signature.getReturnKind() != Kind.Void) { + transferredValues++; + } + return transferredValues; + } - double maxSize = GraalOptions.MaximumGreedyInlineSize; - double inlineRatio = Math.min(GraalOptions.RatioCapForInlining, getRelevance(info.invoke())); - maxSize = Math.pow(GraalOptions.NestedInliningSizeRatio, info.level()) * maxSize * inlineRatio; - maxSize = Math.max(maxSize, GraalOptions.MaximumTrivialSize); - - return decideSizeBasedInlining(info, maxSize); + private static int countInvokeUsages(InlineInfo info) { + // inlining calls with lots of usages simplifies the caller + int usages = 0; + for (Node n : info.invoke().node().usages()) { + if (!(n instanceof FrameState)) { + usages++; + } + } + return usages; } - } - private static class BytecodeSizeBasedWeightComputationPolicy implements WeightComputationPolicy { + private int countMoreSpecificArgumentInfo(InlineInfo info) { + /* + * inlining invokes where the caller has very specific information about the passed + * argument simplifies the callee + */ + int moreSpecificArgumentInfo = 0; + boolean isStatic = info.invoke().methodCallTarget().isStatic(); + int signatureOffset = isStatic ? 0 : 1; + NodeInputList arguments = info.invoke().methodCallTarget().arguments(); + ResolvedJavaMethod targetMethod = info.invoke().methodCallTarget().targetMethod(); + ResolvedJavaType methodHolderClass = targetMethod.getDeclaringClass(); + Signature signature = targetMethod.getSignature(); - @Override - public double computeWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke, boolean preferredInvoke) { - if (GraalOptions.AlwaysInlineIntrinsics && InliningUtil.canIntrinsify(method)) { - return 0; + for (int i = 0; i < arguments.size(); i++) { + Node n = arguments.get(i); + if (n instanceof ConstantNode) { + moreSpecificArgumentInfo++; + } else if (n instanceof ValueNode && !((ValueNode) n).kind().isPrimitive()) { + ResolvedJavaType actualType = ((ValueNode) n).stamp().javaType(runtime); + JavaType declaredType; + if (i == 0 && !isStatic) { + declaredType = methodHolderClass; + } else { + declaredType = signature.getParameterType(i - signatureOffset, methodHolderClass); + } + + if (declaredType instanceof ResolvedJavaType && !actualType.equals(declaredType) && ((ResolvedJavaType) declaredType).isAssignableFrom(actualType)) { + moreSpecificArgumentInfo++; + } + } + } - double codeSize = method.getCodeSize(); - if (preferredInvoke) { - codeSize = codeSize / GraalOptions.BoostInliningForEscapeAnalysis; - } - return codeSize; + return moreSpecificArgumentInfo; } - } - private static class ComplexityBasedWeightComputationPolicy implements WeightComputationPolicy { - - @Override - public double computeWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke, boolean preferredInvoke) { - if (GraalOptions.AlwaysInlineIntrinsics && InliningUtil.canIntrinsify(method)) { - return 0; + private static int bytecodeCodeSize(InlineInfo info) { + int result = 0; + for (int i = 0; i < info.numberOfMethods(); i++) { + result += info.methodAt(i).getCodeSize(); } + return result; + } - double complexity = method.getCompilationComplexity(); - if (preferredInvoke) { - complexity = complexity / GraalOptions.BoostInliningForEscapeAnalysis; + private static int compilationComplexity(InlineInfo info) { + int result = 0; + for (int i = 0; i < info.numberOfMethods(); i++) { + result += info.methodAt(i).getCompilationComplexity(); } - return complexity; + return result; } - } - private static class CompiledCodeSizeWeightComputationPolicy implements WeightComputationPolicy { + private static int compiledCodeSize(InlineInfo info) { + int result = 0; + for (int i = 0; i < info.numberOfMethods(); i++) { + result += info.methodAt(i).getCompiledCodeSize(); + } + return result; + } - @Override - public double computeWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke, boolean preferredInvoke) { - if (GraalOptions.AlwaysInlineIntrinsics && InliningUtil.canIntrinsify(method)) { - return 0; + private static boolean onlyIntrinsics(InlineInfo info) { + for (int i = 0; i < info.numberOfMethods(); i++) { + if (!InliningUtil.canIntrinsify(info.methodAt(i))) { + return false; + } } - - int compiledCodeSize = method.getCompiledCodeSize(); - return compiledCodeSize > 0 ? compiledCodeSize : method.getCodeSize() * 10; + return true; } } private static class CFInliningPolicy implements InliningPolicy { private final InliningDecision inliningDecision; - private final WeightComputationPolicy weightComputationPolicy; private final Collection hints; private final Assumptions assumptions; private final OptimisticOptimizations optimisticOpts; @@ -325,10 +333,8 @@ private NodeBitMap visitedFixedNodes; private FixedNode invokePredecessor; - public CFInliningPolicy(InliningDecision inliningPolicy, WeightComputationPolicy weightComputationPolicy, Collection hints, Assumptions assumptions, - OptimisticOptimizations optimisticOpts) { + public CFInliningPolicy(InliningDecision inliningPolicy, Collection hints, Assumptions assumptions, OptimisticOptimizations optimisticOpts) { this.inliningDecision = inliningPolicy; - this.weightComputationPolicy = weightComputationPolicy; this.hints = hints; this.assumptions = assumptions; this.optimisticOpts = optimisticOpts; @@ -347,7 +353,7 @@ public InlineInfo next() { Invoke invoke = sortedInvokes.pop(); - InlineInfo info = InliningUtil.getInlineInfo(invoke, assumptions, this, optimisticOpts); + InlineInfo info = InliningUtil.getInlineInfo(invoke, assumptions, optimisticOpts); if (info != null) { invokePredecessor = (FixedNode) info.invoke().predecessor(); assert invokePredecessor.isAlive(); @@ -368,171 +374,105 @@ } public void scanInvokes(Iterable newNodes) { - scanGraphForInvokes(invokePredecessor); + assert invokePredecessor.isAlive(); + int invokes = scanGraphForInvokes(invokePredecessor); + assert invokes == countInvokes(newNodes); } - private void scanGraphForInvokes(FixedNode start) { + private int scanGraphForInvokes(FixedNode start) { ArrayList invokes = new InliningIterator(start, visitedFixedNodes).apply(); // insert the newly found invokes in their correct control-flow order for (int i = invokes.size() - 1; i >= 0; i--) { - sortedInvokes.addFirst(invokes.get(i)); - } - } - - public double inliningWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke) { - boolean preferredInvoke = hints != null && hints.contains(invoke); - return weightComputationPolicy.computeWeight(caller, method, invoke, preferredInvoke); - } - } - - private static class PriorityInliningPolicy implements InliningPolicy { + Invoke invoke = invokes.get(i); + assert !sortedInvokes.contains(invoke); + sortedInvokes.addFirst(invoke); - private final InliningDecision inliningDecision; - private final WeightComputationPolicy weightComputationPolicy; - private final Collection hints; - private final Assumptions assumptions; - private final OptimisticOptimizations optimisticOpts; - private final PriorityQueue sortedCandidates; - - public PriorityInliningPolicy(InliningDecision inliningPolicy, WeightComputationPolicy weightComputationPolicy, Collection hints, Assumptions assumptions, - OptimisticOptimizations optimisticOpts) { - this.inliningDecision = inliningPolicy; - this.weightComputationPolicy = weightComputationPolicy; - this.hints = hints; - this.assumptions = assumptions; - this.optimisticOpts = optimisticOpts; - sortedCandidates = new PriorityQueue<>(); - } - - public boolean continueInlining(StructuredGraph graph) { - if (graph.getNodeCount() >= GraalOptions.MaximumDesiredSize) { - InliningUtil.logInliningDecision("inlining is cut off by MaximumDesiredSize"); - metricInliningStoppedByMaxDesiredSize.increment(); - return false; } - return !sortedCandidates.isEmpty(); + return invokes.size(); } - public InlineInfo next() { - // refresh cached info before using it (it might have been in the queue for a long time) - InlineInfo info = sortedCandidates.remove(); - return InliningUtil.getInlineInfo(info.invoke(), assumptions, this, optimisticOpts); - } - - @Override - public boolean isWorthInlining(InlineInfo info) { - return inliningDecision.isWorthInlining(info); - } - - @SuppressWarnings("unchecked") - public void initialize(StructuredGraph graph) { - if (hints == null) { - scanInvokes(graph.getNodes(InvokeNode.class)); - scanInvokes(graph.getNodes(InvokeWithExceptionNode.class)); - } else { - scanInvokes((Iterable) (Iterable) hints); - } - } - - public void scanInvokes(Iterable nodes) { - for (Node node : nodes) { - if (node != null) { - if (node instanceof Invoke) { - Invoke invoke = (Invoke) node; - scanInvoke(invoke); - } - for (Node usage : node.usages().filterInterface(Invoke.class).snapshot()) { - scanInvoke((Invoke) usage); - } + private static int countInvokes(Iterable nodes) { + int count = 0; + for (Node n : nodes) { + if (n instanceof Invoke) { + count++; } } - } - - private void scanInvoke(Invoke invoke) { - InlineInfo info = InliningUtil.getInlineInfo(invoke, assumptions, this, optimisticOpts); - if (info != null) { - sortedCandidates.add(info); - } - } - - @Override - public double inliningWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke) { - boolean preferredInvoke = hints != null && hints.contains(invoke); - return weightComputationPolicy.computeWeight(caller, method, invoke, preferredInvoke); + return count; } } private static class InliningIterator { private final FixedNode start; - private final NodeBitMap processedNodes; - private final Deque nodeQueue; private final NodeBitMap queuedNodes; public InliningIterator(FixedNode start, NodeBitMap visitedFixedNodes) { this.start = start; - this.processedNodes = visitedFixedNodes; - this.nodeQueue = new ArrayDeque<>(); - this.queuedNodes = visitedFixedNodes.copy(); - + this.queuedNodes = visitedFixedNodes; assert start.isAlive(); } public ArrayList apply() { ArrayList invokes = new ArrayList<>(); - FixedNode current = start; - do { + FixedNode current; + forcedQueue(start); + + while ((current = nextQueuedNode()) != null) { assert current.isAlive(); - processedNodes.mark(current); - if (current instanceof InvokeWithExceptionNode || current instanceof InvokeNode) { - invokes.add((Invoke) current); + if (current instanceof Invoke) { + if (current != start) { + invokes.add((Invoke) current); + } queueSuccessors(current); - current = nextQueuedNode(); } else if (current instanceof LoopBeginNode) { - current = ((LoopBeginNode) current).next(); - assert current != null; + queueSuccessors(current); } else if (current instanceof LoopEndNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof MergeNode) { - current = ((MergeNode) current).next(); - assert current != null; + queueSuccessors(current); } else if (current instanceof FixedWithNextNode) { queueSuccessors(current); - current = nextQueuedNode(); } else if (current instanceof EndNode) { queueMerge((EndNode) current); - current = nextQueuedNode(); } else if (current instanceof DeoptimizeNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof ReturnNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof UnwindNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof ControlSplitNode) { queueSuccessors(current); - current = nextQueuedNode(); } else { assert false : current; } - } while (current != null); + } return invokes; } private void queueSuccessors(FixedNode x) { for (Node node : x.successors()) { - if (node != null && !queuedNodes.isMarked(node)) { - queuedNodes.mark(node); - nodeQueue.addFirst((FixedNode) node); - } + queue(node); } } + private void queue(Node node) { + if (node != null && !queuedNodes.isMarked(node)) { + forcedQueue(node); + } + } + + private void forcedQueue(Node node) { + queuedNodes.mark(node); + nodeQueue.addFirst((FixedNode) node); + } + private FixedNode nextQueuedNode() { if (nodeQueue.isEmpty()) { return null; @@ -553,7 +493,7 @@ private boolean visitedAllEnds(MergeNode merge) { for (int i = 0; i < merge.forwardEndCount(); i++) { - if (!processedNodes.isMarked(merge.forwardEndAt(i))) { + if (!queuedNodes.isMarked(merge.forwardEndAt(i))) { return false; } } @@ -561,49 +501,8 @@ } } - private static InliningPolicy createInliningPolicy(Assumptions assumptions, OptimisticOptimizations optimisticOpts, Collection hints) { - switch (GraalOptions.InliningPolicy) { - case 0: - return new CFInliningPolicy(createInliningDecision(), createWeightComputationPolicy(), hints, assumptions, optimisticOpts); - case 1: - return new PriorityInliningPolicy(createInliningDecision(), createWeightComputationPolicy(), hints, assumptions, optimisticOpts); - default: - GraalInternalError.shouldNotReachHere(); - return null; - } - } - - private static InliningDecision createInliningDecision() { - switch (GraalOptions.InliningDecision) { - case 1: - return new C1StaticSizeBasedInliningDecision(); - case 2: - return new MinimumCodeSizeBasedInliningDecision(); - case 3: - return new DynamicSizeBasedInliningDecision(); - case 4: - return new GreedySizeBasedInliningDecision(); - case 5: - return new GreedyMachineCodeInliningDecision(); - default: - GraalInternalError.shouldNotReachHere(); - return null; - } - } - - private static WeightComputationPolicy createWeightComputationPolicy() { - switch (GraalOptions.WeightComputationPolicy) { - case 0: - throw new GraalInternalError("removed because of invokation counter changes"); - case 1: - return new BytecodeSizeBasedWeightComputationPolicy(); - case 2: - return new ComplexityBasedWeightComputationPolicy(); - case 3: - return new CompiledCodeSizeWeightComputationPolicy(); - default: - GraalInternalError.shouldNotReachHere(); - return null; - } + private static InliningPolicy createInliningPolicy(GraalCodeCacheProvider runtime, Assumptions assumptions, OptimisticOptimizations optimisticOpts, Collection hints) { + InliningDecision inliningDecision = new GreedySizeBasedInliningDecision(runtime, hints); + return new CFInliningPolicy(inliningDecision, hints, assumptions, optimisticOpts); } } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/InliningUtil.java Mon Feb 04 20:23:57 2013 +0100 @@ -70,18 +70,13 @@ void scanInvokes(Iterable newNodes); - double inliningWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke); - boolean isWorthInlining(InlineInfo info); } - public interface WeightComputationPolicy { + public static boolean logNotInlinedMethod(InlineInfo info, String msg, Object... args) { - double computeWeight(ResolvedJavaMethod caller, ResolvedJavaMethod method, Invoke invoke, boolean preferredInvoke); - } - - public static void logNotInlinedMethod(InlineInfo info, String msg, Object... args) { logInliningDecision(info, false, msg, args); + return false; } public static void logInliningDecision(InlineInfo info, boolean success, String msg, final Object... args) { @@ -99,6 +94,11 @@ }); } + public static boolean logInlinedMethod(InlineInfo info, String string, Object... args) { + logInliningDecision(info, true, string, args); + return true; + } + private static boolean logNotInlinedMethodAndReturnFalse(Invoke invoke, String msg) { if (shouldLogInliningDecision()) { String methodString = invoke.toString() + (invoke.callTarget() == null ? " callTarget=null" : invoke.callTarget().targetName()); @@ -135,7 +135,7 @@ logInliningDecision(inliningMsg, args); } - private static boolean shouldLogInliningDecision() { + public static boolean shouldLogInliningDecision() { return Debug.scope(inliningDecisionsScopeString, new Callable() { public Boolean call() { @@ -178,49 +178,43 @@ * The weight is the amortized weight of the additional code - so smaller is better. The level * is the number of nested inlinings that lead to this invoke. */ - public interface InlineInfo extends Comparable { + public interface InlineInfo { Invoke invoke(); - double weight(); - int level(); - int compiledCodeSize(); + int numberOfMethods(); - int compareTo(InlineInfo o); + ResolvedJavaMethod methodAt(int index); /** * Performs the inlining described by this object and returns the node that represents the * return value of the inlined method (or null for void methods and methods that have no * non-exceptional exit). + **/ + void inline(StructuredGraph graph, GraalCodeCacheProvider runtime, InliningCallback callback, Assumptions assumptions); + + /** + * Try to make the call static bindable to avoid interface and virtual method calls. */ - void inline(StructuredGraph graph, GraalCodeCacheProvider runtime, InliningCallback callback, Assumptions assumptions); + void tryToDevirtualizeInvoke(StructuredGraph graph, GraalCodeCacheProvider runtime, Assumptions assumptions); } public abstract static class AbstractInlineInfo implements InlineInfo { protected final Invoke invoke; - protected final double weight; - public AbstractInlineInfo(Invoke invoke, double weight) { + public AbstractInlineInfo(Invoke invoke) { this.invoke = invoke; - this.weight = weight; } @Override - public int compareTo(InlineInfo o) { - return (weight < o.weight()) ? -1 : (weight > o.weight()) ? 1 : 0; - } - public Invoke invoke() { return invoke; } - public double weight() { - return weight; - } - + @Override public int level() { return computeInliningLevel(invoke); } @@ -260,7 +254,7 @@ } } - private static StructuredGraph getGraph(final ResolvedJavaMethod concrete, final InliningCallback callback) { + protected static StructuredGraph getGraph(final ResolvedJavaMethod concrete, final InliningCallback callback) { return Debug.scope("GetInliningGraph", concrete, new Callable() { @Override @@ -270,6 +264,12 @@ } }); } + + protected void replaceInvokeCallTarget(StructuredGraph graph, InvokeKind invokeKind, ResolvedJavaMethod targetMethod) { + MethodCallTargetNode oldCallTarget = invoke.methodCallTarget(); + MethodCallTargetNode newCallTarget = graph.add(new MethodCallTargetNode(invokeKind, targetMethod, oldCallTarget.arguments().toArray(new ValueNode[0]), oldCallTarget.returnType())); + invoke.node().replaceFirstInput(oldCallTarget, newCallTarget); + } } /** @@ -280,8 +280,8 @@ public final ResolvedJavaMethod concrete; - public ExactInlineInfo(Invoke invoke, double weight, ResolvedJavaMethod concrete) { - super(invoke, weight); + public ExactInlineInfo(Invoke invoke, ResolvedJavaMethod concrete) { + super(invoke); this.concrete = concrete; } @@ -291,8 +291,19 @@ } @Override - public int compiledCodeSize() { - return InliningUtil.compiledCodeSize(concrete); + public void tryToDevirtualizeInvoke(StructuredGraph graph, GraalCodeCacheProvider runtime, Assumptions assumptions) { + // nothing todo, can already be bound statically + } + + @Override + public int numberOfMethods() { + return 1; + } + + @Override + public ResolvedJavaMethod methodAt(int index) { + assert index == 0; + return concrete; } @Override @@ -311,20 +322,36 @@ public final ResolvedJavaMethod concrete; public final ResolvedJavaType type; - public TypeGuardInlineInfo(Invoke invoke, double weight, ResolvedJavaMethod concrete, ResolvedJavaType type) { - super(invoke, weight); + public TypeGuardInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, ResolvedJavaType type) { + super(invoke); this.concrete = concrete; this.type = type; } @Override - public int compiledCodeSize() { - return InliningUtil.compiledCodeSize(concrete); + public int numberOfMethods() { + return 1; + } + + @Override + public ResolvedJavaMethod methodAt(int index) { + assert index == 0; + return concrete; } @Override public void inline(StructuredGraph graph, GraalCodeCacheProvider runtime, InliningCallback callback, Assumptions assumptions) { - // receiver null check must be before the type check + createGuard(graph, runtime); + inline(invoke, concrete, callback, assumptions, false); + } + + @Override + public void tryToDevirtualizeInvoke(StructuredGraph graph, GraalCodeCacheProvider runtime, Assumptions assumptions) { + createGuard(graph, runtime); + replaceInvokeCallTarget(graph, InvokeKind.Special, concrete); + } + + private void createGuard(StructuredGraph graph, GraalCodeCacheProvider runtime) { InliningUtil.receiverNullCheck(invoke); ValueNode receiver = invoke.methodCallTarget().receiver(); ConstantNode typeHub = ConstantNode.forConstant(type.getEncoding(Representation.ObjectHub), runtime, graph); @@ -340,8 +367,6 @@ graph.addBeforeFixed(invoke.node(), receiverHub); graph.addBeforeFixed(invoke.node(), guard); graph.addBeforeFixed(invoke.node(), anchor); - - inline(invoke, concrete, callback, assumptions, false); } @Override @@ -362,8 +387,8 @@ public final int[] typesToConcretes; public final double notRecordedTypeProbability; - public MultiTypeGuardInlineInfo(Invoke invoke, double weight, ArrayList concretes, ArrayList ptypes, int[] typesToConcretes, double notRecordedTypeProbability) { - super(invoke, weight); + public MultiTypeGuardInlineInfo(Invoke invoke, ArrayList concretes, ArrayList ptypes, int[] typesToConcretes, double notRecordedTypeProbability) { + super(invoke); assert concretes.size() > 0 && concretes.size() <= ptypes.size() : "must have at least one method but no more than types methods"; assert ptypes.size() == typesToConcretes.length : "array lengths must match"; @@ -374,33 +399,37 @@ } @Override - public int compiledCodeSize() { - int result = 0; - for (ResolvedJavaMethod m : concretes) { - result += InliningUtil.compiledCodeSize(m); - } - return result; + public int numberOfMethods() { + return concretes.size(); + } + + @Override + public ResolvedJavaMethod methodAt(int index) { + assert index >= 0 && index < concretes.size(); + return concretes.get(index); } @Override public void inline(StructuredGraph graph, GraalCodeCacheProvider runtime, InliningCallback callback, Assumptions assumptions) { - int numberOfMethods = concretes.size(); - boolean hasReturnValue = invoke.node().kind() != Kind.Void; - // receiver null check must be the first node InliningUtil.receiverNullCheck(invoke); - if (numberOfMethods > 1 || shouldFallbackToInvoke()) { - inlineMultipleMethods(graph, callback, assumptions, numberOfMethods, hasReturnValue); + if (hasSingleMethod()) { + inlineSingleMethod(graph, callback, assumptions); } else { - inlineSingleMethod(graph, callback, assumptions); + inlineMultipleMethods(graph, callback, assumptions); } } + private boolean hasSingleMethod() { + return concretes.size() == 1 && !shouldFallbackToInvoke(); + } + private boolean shouldFallbackToInvoke() { return notRecordedTypeProbability > 0; } - private void inlineMultipleMethods(StructuredGraph graph, InliningCallback callback, Assumptions assumptions, int numberOfMethods, boolean hasReturnValue) { + private void inlineMultipleMethods(StructuredGraph graph, InliningCallback callback, Assumptions assumptions) { + int numberOfMethods = concretes.size(); FixedNode continuation = invoke.next(); ValueNode originalReceiver = invoke.methodCallTarget().receiver(); @@ -410,7 +439,7 @@ returnMerge.setStateAfter(invoke.stateAfter().duplicate(invoke.stateAfter().bci)); PhiNode returnValuePhi = null; - if (hasReturnValue) { + if (invoke.node().kind() != Kind.Void) { returnValuePhi = graph.unique(new PhiNode(invoke.node().kind(), returnMerge)); } @@ -465,16 +494,13 @@ assert invoke.node().isAlive(); // replace the invoke with a switch on the type of the actual receiver - Kind hubKind = invoke.methodCallTarget().targetMethod().getDeclaringClass().getEncoding(Representation.ObjectHub).getKind(); - LoadHubNode receiverHub = graph.add(new LoadHubNode(invoke.methodCallTarget().receiver(), hubKind)); - graph.addBeforeFixed(invoke.node(), receiverHub); - FixedNode dispatchOnType = createDispatchOnType(graph, receiverHub, successors); + createDispatchOnTypeBeforeInvoke(graph, successors, false); assert invoke.next() == continuation; invoke.setNext(null); returnMerge.setNext(continuation); invoke.node().replaceAtUsages(returnValuePhi); - invoke.node().replaceAndDelete(dispatchOnType); + invoke.node().replaceAndDelete(null); ArrayList replacements = new ArrayList<>(); @@ -544,45 +570,52 @@ return commonType; } + private ResolvedJavaType getLeastCommonType() { + ResolvedJavaType result = getLeastCommonType(0); + for (int i = 1; i < concretes.size(); i++) { + result = result.findLeastCommonAncestor(getLeastCommonType(i)); + } + return result; + } + private void inlineSingleMethod(StructuredGraph graph, InliningCallback callback, Assumptions assumptions) { assert concretes.size() == 1 && ptypes.size() > 1 && !shouldFallbackToInvoke() && notRecordedTypeProbability == 0; BeginNode calleeEntryNode = graph.add(new BeginNode()); calleeEntryNode.setProbability(invoke.probability()); - Kind hubKind = invoke.methodCallTarget().targetMethod().getDeclaringClass().getEncoding(Representation.ObjectHub).getKind(); - LoadHubNode receiverHub = graph.add(new LoadHubNode(invoke.methodCallTarget().receiver(), hubKind)); - graph.addBeforeFixed(invoke.node(), receiverHub); - BeginNode unknownTypeSux = BeginNode.begin(graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated))); + BeginNode unknownTypeSux = createUnknownTypeSuccessor(graph); BeginNode[] successors = new BeginNode[]{calleeEntryNode, unknownTypeSux}; - FixedNode dispatchOnType = createDispatchOnType(graph, receiverHub, successors); + createDispatchOnTypeBeforeInvoke(graph, successors, false); - FixedWithNextNode pred = (FixedWithNextNode) invoke.node().predecessor(); - pred.setNext(dispatchOnType); calleeEntryNode.setNext(invoke.node()); ResolvedJavaMethod concrete = concretes.get(0); inline(invoke, concrete, callback, assumptions, false); } - private FixedNode createDispatchOnType(StructuredGraph graph, LoadHubNode hub, BeginNode[] successors) { + private void createDispatchOnTypeBeforeInvoke(StructuredGraph graph, BeginNode[] successors, boolean invokeIsOnlySuccessor) { assert ptypes.size() > 1; + Kind hubKind = invoke.methodCallTarget().targetMethod().getDeclaringClass().getEncoding(Representation.ObjectHub).getKind(); + LoadHubNode hub = graph.add(new LoadHubNode(invoke.methodCallTarget().receiver(), hubKind)); + graph.addBeforeFixed(invoke.node(), hub); + ResolvedJavaType[] keys = new ResolvedJavaType[ptypes.size()]; double[] keyProbabilities = new double[ptypes.size() + 1]; int[] keySuccessors = new int[ptypes.size() + 1]; for (int i = 0; i < ptypes.size(); i++) { keys[i] = ptypes.get(i).getType(); keyProbabilities[i] = ptypes.get(i).getProbability(); - keySuccessors[i] = typesToConcretes[i]; + keySuccessors[i] = invokeIsOnlySuccessor ? 0 : typesToConcretes[i]; assert keySuccessors[i] < successors.length - 1 : "last successor is the unknownTypeSux"; } keyProbabilities[keyProbabilities.length - 1] = notRecordedTypeProbability; keySuccessors[keySuccessors.length - 1] = successors.length - 1; TypeSwitchNode typeSwitch = graph.add(new TypeSwitchNode(hub, successors, keys, keyProbabilities, keySuccessors)); - - return typeSwitch; + FixedWithNextNode pred = (FixedWithNextNode) invoke.node().predecessor(); + pred.setNext(typeSwitch); } private static BeginNode createInvocationBlock(StructuredGraph graph, Invoke invoke, MergeNode returnMerge, PhiNode returnValuePhi, MergeNode exceptionMerge, PhiNode exceptionObjectPhi, @@ -645,6 +678,56 @@ } @Override + public void tryToDevirtualizeInvoke(StructuredGraph graph, GraalCodeCacheProvider runtime, Assumptions assumptions) { + if (hasSingleMethod()) { + tryToDevirtualizeSingleMethod(graph); + } else { + tryToDevirtualizeMultipleMethods(graph); + } + } + + private void tryToDevirtualizeSingleMethod(StructuredGraph graph) { + devirtualizeWithTypeSwitch(graph, InvokeKind.Special, concretes.get(0)); + } + + private void tryToDevirtualizeMultipleMethods(StructuredGraph graph) { + MethodCallTargetNode methodCallTarget = invoke.methodCallTarget(); + if (methodCallTarget.invokeKind() == InvokeKind.Interface) { + ResolvedJavaMethod targetMethod = methodCallTarget.targetMethod(); + ResolvedJavaType leastCommonType = getLeastCommonType(); + // check if we have a common base type that implements the interface -> in that case +// we have a vtable entry for the interface method and can use a less expensive virtual call + if (!leastCommonType.isInterface() && targetMethod.getDeclaringClass().isAssignableFrom(leastCommonType)) { + ResolvedJavaMethod baseClassTargetMethod = leastCommonType.resolveMethod(targetMethod); + if (baseClassTargetMethod != null) { + devirtualizeWithTypeSwitch(graph, InvokeKind.Virtual, leastCommonType.resolveMethod(targetMethod)); + } + } + } + } + + private void devirtualizeWithTypeSwitch(StructuredGraph graph, InvokeKind kind, ResolvedJavaMethod target) { + InliningUtil.receiverNullCheck(invoke); + + BeginNode invocationEntry = graph.add(new BeginNode()); + invocationEntry.setProbability(invoke.probability()); + + BeginNode unknownTypeSux = createUnknownTypeSuccessor(graph); + BeginNode[] successors = new BeginNode[]{invocationEntry, unknownTypeSux}; + createDispatchOnTypeBeforeInvoke(graph, successors, true); + + invocationEntry.setNext(invoke.node()); + ValueNode receiver = invoke.methodCallTarget().receiver(); + PiNode anchoredReceiver = createAnchoredReceiver(graph, invocationEntry, target.getDeclaringClass(), receiver, false); + invoke.callTarget().replaceFirstInput(receiver, anchoredReceiver); + replaceInvokeCallTarget(graph, kind, target); + } + + private static BeginNode createUnknownTypeSuccessor(StructuredGraph graph) { + return BeginNode.begin(graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TypeCheckedInliningViolated))); + } + + @Override public String toString() { StringBuilder builder = new StringBuilder(shouldFallbackToInvoke() ? "megamorphic" : "polymorphic"); builder.append(", "); @@ -674,8 +757,8 @@ private final Assumption takenAssumption; - public AssumptionInlineInfo(Invoke invoke, double weight, ResolvedJavaMethod concrete, Assumption takenAssumption) { - super(invoke, weight, concrete); + public AssumptionInlineInfo(Invoke invoke, ResolvedJavaMethod concrete, Assumption takenAssumption) { + super(invoke, concrete); this.takenAssumption = takenAssumption; } @@ -688,6 +771,12 @@ } @Override + public void tryToDevirtualizeInvoke(StructuredGraph graph, GraalCodeCacheProvider runtime, Assumptions assumptions) { + assumptions.record(takenAssumption); + replaceInvokeCallTarget(graph, InvokeKind.Special, concrete); + } + + @Override public String toString() { return "assumption " + MetaUtil.format("%H.%n(%p):%r", concrete); } @@ -697,10 +786,9 @@ * Determines if inlining is possible at the given invoke node. * * @param invoke the invoke that should be inlined - * @param inliningPolicy used to determine the weight of a specific inlining * @return an instance of InlineInfo, or null if no inlining is possible at the given invoke */ - public static InlineInfo getInlineInfo(Invoke invoke, Assumptions assumptions, InliningPolicy inliningPolicy, OptimisticOptimizations optimisticOpts) { + public static InlineInfo getInlineInfo(Invoke invoke, Assumptions assumptions, OptimisticOptimizations optimisticOpts) { if (!checkInvokeConditions(invoke)) { return null; } @@ -709,7 +797,7 @@ ResolvedJavaMethod targetMethod = callTarget.targetMethod(); if (callTarget.invokeKind() == InvokeKind.Special || targetMethod.canBeStaticallyBound()) { - return getExactInlineInfo(invoke, inliningPolicy, optimisticOpts, caller, targetMethod); + return getExactInlineInfo(invoke, optimisticOpts, targetMethod); } assert callTarget.invokeKind() == InvokeKind.Virtual || callTarget.invokeKind() == InvokeKind.Interface; @@ -724,57 +812,49 @@ holder = receiverType; if (receiverStamp.isExactType()) { assert targetMethod.getDeclaringClass().isAssignableFrom(holder) : holder + " subtype of " + targetMethod.getDeclaringClass() + " for " + targetMethod; - return getExactInlineInfo(invoke, inliningPolicy, optimisticOpts, caller, holder.resolveMethod(targetMethod)); + return getExactInlineInfo(invoke, optimisticOpts, holder.resolveMethod(targetMethod)); } } } if (holder.isArray()) { // arrays can be treated as Objects - return getExactInlineInfo(invoke, inliningPolicy, optimisticOpts, caller, holder.resolveMethod(targetMethod)); + return getExactInlineInfo(invoke, optimisticOpts, holder.resolveMethod(targetMethod)); } - // TODO (chaeubl): we could also use the type determined after assumptions for the - // type-checked inlining case as it might have an effect on type filtering if (assumptions.useOptimisticAssumptions()) { ResolvedJavaType uniqueSubtype = holder.findUniqueConcreteSubtype(); if (uniqueSubtype != null) { - return getAssumptionInlineInfo(invoke, inliningPolicy, optimisticOpts, caller, uniqueSubtype.resolveMethod(targetMethod), new Assumptions.ConcreteSubtype(holder, uniqueSubtype)); + return getAssumptionInlineInfo(invoke, optimisticOpts, uniqueSubtype.resolveMethod(targetMethod), new Assumptions.ConcreteSubtype(holder, uniqueSubtype)); } ResolvedJavaMethod concrete = holder.findUniqueConcreteMethod(targetMethod); if (concrete != null) { - return getAssumptionInlineInfo(invoke, inliningPolicy, optimisticOpts, caller, concrete, new Assumptions.ConcreteMethod(targetMethod, holder, concrete)); + return getAssumptionInlineInfo(invoke, optimisticOpts, concrete, new Assumptions.ConcreteMethod(targetMethod, holder, concrete)); } - - // TODO (chaeubl): C1 has one more assumption in the case of interfaces } // type check based inlining - return getTypeCheckedInlineInfo(invoke, inliningPolicy, caller, holder, targetMethod, optimisticOpts); + return getTypeCheckedInlineInfo(invoke, caller, holder, targetMethod, optimisticOpts); } - private static InlineInfo getAssumptionInlineInfo(Invoke invoke, InliningPolicy inliningPolicy, OptimisticOptimizations optimisticOpts, ResolvedJavaMethod caller, ResolvedJavaMethod concrete, - Assumption takenAssumption) { + private static InlineInfo getAssumptionInlineInfo(Invoke invoke, OptimisticOptimizations optimisticOpts, ResolvedJavaMethod concrete, Assumption takenAssumption) { assert !Modifier.isAbstract(concrete.getModifiers()); if (!checkTargetConditions(invoke, concrete, optimisticOpts)) { return null; } - double weight = inliningPolicy.inliningWeight(caller, concrete, invoke); - return new AssumptionInlineInfo(invoke, weight, concrete, takenAssumption); + return new AssumptionInlineInfo(invoke, concrete, takenAssumption); } - private static InlineInfo getExactInlineInfo(Invoke invoke, InliningPolicy inliningPolicy, OptimisticOptimizations optimisticOpts, ResolvedJavaMethod caller, ResolvedJavaMethod targetMethod) { + private static InlineInfo getExactInlineInfo(Invoke invoke, OptimisticOptimizations optimisticOpts, ResolvedJavaMethod targetMethod) { assert !Modifier.isAbstract(targetMethod.getModifiers()); if (!checkTargetConditions(invoke, targetMethod, optimisticOpts)) { return null; } - double weight = inliningPolicy.inliningWeight(caller, targetMethod, invoke); - return new ExactInlineInfo(invoke, weight, targetMethod); + return new ExactInlineInfo(invoke, targetMethod); } - private static InlineInfo getTypeCheckedInlineInfo(Invoke invoke, InliningPolicy inliningPolicy, ResolvedJavaMethod caller, ResolvedJavaType holder, ResolvedJavaMethod targetMethod, - OptimisticOptimizations optimisticOpts) { + private static InlineInfo getTypeCheckedInlineInfo(Invoke invoke, ResolvedJavaMethod caller, ResolvedJavaType holder, ResolvedJavaMethod targetMethod, OptimisticOptimizations optimisticOpts) { ProfilingInfo profilingInfo = caller.getProfilingInfo(); JavaTypeProfile typeProfile = profilingInfo.getTypeProfile(invoke.bci()); if (typeProfile == null) { @@ -798,8 +878,7 @@ if (!checkTargetConditions(invoke, concrete, optimisticOpts)) { return null; } - double weight = inliningPolicy.inliningWeight(caller, concrete, invoke); - return new TypeGuardInlineInfo(invoke, weight, concrete, type); + return new TypeGuardInlineInfo(invoke, concrete, type); } else { invoke.setPolymorphic(true); @@ -813,14 +892,6 @@ notRecordedTypeProbability * 100); } - // TODO (chaeubl) inlining of multiple methods should work differently - // 1. check which methods can be inlined - // 2. for those methods, use weight and probability to compute which of them should be - // inlined - // 3. do the inlining - // a) all seen methods can be inlined -> do so and guard with deopt - // b) some methods can be inlined -> inline them and fall back to invocation if violated - // determine concrete methods and map type to specific method ArrayList concreteMethods = new ArrayList<>(); int[] typesToConcretes = new int[ptypes.size()]; @@ -835,14 +906,12 @@ typesToConcretes[i] = index; } - double totalWeight = 0; for (ResolvedJavaMethod concrete : concreteMethods) { if (!checkTargetConditions(invoke, concrete, optimisticOpts)) { return logNotInlinedMethodAndReturnNull(invoke, targetMethod, "it is a polymorphic method call and at least one invoked method cannot be inlined"); } - totalWeight += inliningPolicy.inliningWeight(caller, concrete, invoke); } - return new MultiTypeGuardInlineInfo(invoke, totalWeight, concreteMethods, ptypes, typesToConcretes, notRecordedTypeProbability); + return new MultiTypeGuardInlineInfo(invoke, concreteMethods, ptypes, typesToConcretes, notRecordedTypeProbability); } } @@ -1033,7 +1102,7 @@ if (node instanceof Invoke) { Invoke newInvoke = (Invoke) node; double newRelevance = newInvoke.inliningRelevance() * invoke.inliningRelevance(); - if (GraalOptions.LimitInlinedProbability) { + if (GraalOptions.LimitInlinedRelevance) { newRelevance = Math.min(newRelevance, invoke.inliningRelevance()); } newInvoke.setInliningRelevance(newRelevance); @@ -1105,14 +1174,6 @@ return (StructuredGraph) target.getCompilerStorage().get(Graph.class); } - private static int compiledCodeSize(ResolvedJavaMethod target) { - if (GraalOptions.AlwaysInlineIntrinsics && canIntrinsify(target)) { - return 0; - } else { - return target.getCompiledCodeSize(); - } - } - public static Class getMacroNodeClass(ResolvedJavaMethod target) { Object result = target.getCompilerStorage().get(Node.class); return result == null ? null : ((Class) result).asSubclass(FixedWithNextNode.class); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java Mon Feb 04 20:23:57 2013 +0100 @@ -43,30 +43,24 @@ static boolean InlineMonomorphicCalls = true; static boolean InlinePolymorphicCalls = true; static boolean InlineMegamorphicCalls = ____; - public static int InliningPolicy = 1; - public static int InliningDecision = 4; - public static int WeightComputationPolicy = 2; - public static int MaximumTrivialSize = 10; public static int MaximumInlineLevel = 30; - public static int MaximumDesiredSize = 3000; + public static int MaximumDesiredSize = 5000; public static int MaximumRecursiveInlining = 1; - public static int SmallCompiledCodeSize = 2200; public static boolean LimitInlinedProbability = ____; - public static boolean UseRelevanceBasedInlining = ____; - // WeightBasedInliningPolicy (0) - public static float InliningSizePenaltyExp = 20; - public static float MaximumInlineWeight = 1.25f; - public static float InliningSizePenalty = 1; - // StaticSizeBasedInliningPolicy (1), MinimumCodeSizeBasedInlining (2), - // DynamicSizeBasedInliningPolicy (3) - public static int MaximumInlineSize = 35; - // GreedySizeBasedInlining (4) - public static int MaximumGreedyInlineSize = 100; - public static int InliningBonusPerTransferredValue = 10; - // Common options for inlining policies 1 to 4 - public static float NestedInliningSizeRatio = 1f; + public static boolean LimitInlinedRelevance = true; public static float BoostInliningForEscapeAnalysis = 2f; - public static float RatioCapForInlining = 1f; + public static float RelevanceCapForInlining = 1f; + + public static int TrivialBytecodeSize = 10; + public static int NormalBytecodeSize = 150; + public static int MaximumBytecodeSize = 500; + public static int TrivialComplexity = 10; + public static int NormalComplexity = 60; + public static int MaximumComplexity = 400; + public static int TrivialCompiledCodeSize = 150; + public static int NormalCompiledCodeSize = 750; + public static int MaximumCompiledCodeSize = 4000; + public static int SmallCompiledCodeSize = 1000; // escape analysis settings public static boolean PartialEscapeAnalysis = true; @@ -80,7 +74,6 @@ // absolute probability analysis public static boolean ProbabilityAnalysis = true; - public static int LoopFrequencyPropagationPolicy = -2; // profiling information public static int DeoptsToDisableOptimisticOptimization = 40; @@ -201,6 +194,7 @@ public static boolean OptTailDuplication = true; public static boolean OptEliminatePartiallyRedundantGuards = true; public static boolean OptFilterProfiledTypes = true; + public static boolean OptDevirtualizeInvokesOptimistically = true; // Intrinsification settings public static boolean IntrinsifyArrayCopy = true; diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/OptimisticOptimizations.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/OptimisticOptimizations.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/OptimisticOptimizations.java Mon Feb 04 20:23:57 2013 +0100 @@ -52,9 +52,10 @@ if (checkDeoptimizations(method.getProfilingInfo(), deoptReason)) { enabledOpts.add(optimization); } else { - // TODO (chaeubl): change to Debug.log when we are sure that optimistic optimizations - // are not disabled - // unnecessarily + /* + * TODO (chaeubl): see GRAAL-75 (remove when we are sure that optimistic optimizations + * are not disabled unnecessarily + */ TTY.println("WARN: deactivated optimistic optimization %s for %s", optimization.name(), MetaUtil.format("%H.%n(%p)", method)); disabledOptimisticOptsMetric.increment(); } @@ -84,6 +85,10 @@ return GraalOptions.InlineMegamorphicCalls && enabledOpts.contains(Optimization.UseTypeCheckedInlining); } + public boolean devirtualizeInvokes() { + return GraalOptions.OptDevirtualizeInvokesOptimistically && enabledOpts.contains(Optimization.UseTypeCheckedInlining); + } + public boolean useExceptionProbability() { return GraalOptions.UseExceptionProbability && enabledOpts.contains(Optimization.UseExceptionProbability); } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ScopedPostOrderNodeIterator.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ScopedPostOrderNodeIterator.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/graph/ScopedPostOrderNodeIterator.java Mon Feb 04 20:23:57 2013 +0100 @@ -30,15 +30,13 @@ public abstract class ScopedPostOrderNodeIterator { - private final NodeBitMap processedNodes; private final Deque nodeQueue; private final NodeBitMap queuedNodes; private final Deque scopes; - protected FixedNode currentScope; + protected FixedNode currentScopeStart; public ScopedPostOrderNodeIterator(StructuredGraph graph) { - this.processedNodes = graph.createNodeBitMap(); this.queuedNodes = graph.createNodeBitMap(); this.nodeQueue = new ArrayDeque<>(); this.scopes = getScopes(graph); @@ -46,64 +44,57 @@ public void apply() { while (!scopes.isEmpty()) { - processedNodes.clearAll(); queuedNodes.clearAll(); - this.currentScope = scopes.pop(); + this.currentScopeStart = scopes.pop(); initializeScope(); processScope(); } } public void processScope() { - FixedNode current = currentScope; - do { + FixedNode current; + queue(currentScopeStart); + + while ((current = nextQueuedNode()) != null) { assert current.isAlive(); - processedNodes.mark(current); if (current instanceof Invoke) { invoke((Invoke) current); queueSuccessors(current); - current = nextQueuedNode(); } else if (current instanceof LoopBeginNode) { queueLoopBeginSuccessors((LoopBeginNode) current); - current = nextQueuedNode(); } else if (current instanceof LoopExitNode) { queueLoopExitSuccessors((LoopExitNode) current); - current = nextQueuedNode(); } else if (current instanceof LoopEndNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof MergeNode) { - current = ((MergeNode) current).next(); - assert current != null; + queueSuccessors(current); } else if (current instanceof FixedWithNextNode) { queueSuccessors(current); - current = nextQueuedNode(); } else if (current instanceof EndNode) { queueMerge((EndNode) current); - current = nextQueuedNode(); } else if (current instanceof DeoptimizeNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof ReturnNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof UnwindNode) { - current = nextQueuedNode(); + // nothing todo } else if (current instanceof ControlSplitNode) { queueSuccessors(current); - current = nextQueuedNode(); } else { assert false : current; } - } while (current != null); + } } protected void queueLoopBeginSuccessors(LoopBeginNode node) { - if (currentScope == node) { + if (currentScopeStart == node) { queue(node.next()); - } else if (currentScope instanceof LoopBeginNode) { + } else if (currentScopeStart instanceof LoopBeginNode) { // so we are currently processing loop A and found another loop B // -> queue all loop exits of B except those that also exit loop A for (LoopExitNode loopExit : node.loopExits()) { - if (!((LoopBeginNode) currentScope).loopExits().contains(loopExit)) { + if (!((LoopBeginNode) currentScopeStart).loopExits().contains(loopExit)) { queue(loopExit); } } @@ -113,7 +104,7 @@ } protected void queueLoopExitSuccessors(LoopExitNode node) { - if (!(currentScope instanceof LoopBeginNode) || !((LoopBeginNode) currentScope).loopExits().contains(node)) { + if (!(currentScopeStart instanceof LoopBeginNode) || !((LoopBeginNode) currentScopeStart).loopExits().contains(node)) { queueSuccessors(node); } } @@ -157,14 +148,13 @@ private void queueMerge(EndNode end) { MergeNode merge = end.merge(); if (!queuedNodes.isMarked(merge) && visitedAllEnds(merge)) { - queuedNodes.mark(merge); - nodeQueue.add(merge); + queue(merge); } } private boolean visitedAllEnds(MergeNode merge) { for (int i = 0; i < merge.forwardEndCount(); i++) { - if (!processedNodes.isMarked(merge.forwardEndAt(i))) { + if (!queuedNodes.isMarked(merge.forwardEndAt(i))) { return false; } } diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Signed.java Mon Feb 04 20:23:57 2013 +0100 @@ -119,6 +119,22 @@ * Compares this Signed with the specified value. * * @param val value to which this Signed is to be compared. + * @return {@code this == val} + */ + boolean equal(Signed val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. + * @return {@code this != val} + */ + boolean notEqual(Signed val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. * @return {@code this < val} */ boolean lessThan(Signed val); @@ -234,6 +250,22 @@ * Compares this Signed with the specified value. * * @param val value to which this Signed is to be compared. + * @return {@code this == val} + */ + boolean equal(int val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. + * @return {@code this != val} + */ + boolean notEqual(int val); + + /** + * Compares this Signed with the specified value. + * + * @param val value to which this Signed is to be compared. * @return {@code this < val} */ boolean lessThan(int val); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Unsigned.java Mon Feb 04 20:23:57 2013 +0100 @@ -115,6 +115,22 @@ * Compares this Unsigned with the specified value. * * @param val value to which this Unsigned is to be compared. + * @return {@code this == val} + */ + boolean equal(Unsigned val); + + /** + * Compares this Unsigned with the specified value. + * + * @param val value to which this Unsigned is to be compared. + * @return {@code this != val} + */ + boolean notEqual(Unsigned val); + + /** + * Compares this Unsigned with the specified value. + * + * @param val value to which this Unsigned is to be compared. * @return {@code this < val} */ boolean belowThan(Unsigned val); @@ -260,6 +276,28 @@ * Therefore, the result is only well-defined for positive right operands. * * @param val value to which this Unsigned is to be compared. + * @return {@code this == val} + */ + boolean equal(int val); + + /** + * Compares this Unsigned with the specified value. + *

+ * Note that the right operand is a signed value, while the operation is performed unsigned. + * Therefore, the result is only well-defined for positive right operands. + * + * @param val value to which this Unsigned is to be compared. + * @return {@code this != val} + */ + boolean notEqual(int val); + + /** + * Compares this Unsigned with the specified value. + *

+ * Note that the right operand is a signed value, while the operation is performed unsigned. + * Therefore, the result is only well-defined for positive right operands. + * + * @param val value to which this Unsigned is to be compared. * @return {@code this < val} */ boolean belowThan(int val); diff -r ec6dc1326b15 -r 14720c279875 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 Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/Word.java Mon Feb 04 20:23:57 2013 +0100 @@ -25,9 +25,9 @@ import static com.oracle.graal.graph.UnsafeAccess.*; import java.lang.annotation.*; -import java.util.concurrent.*; import com.oracle.graal.api.code.*; +import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.calc.*; @@ -415,6 +415,52 @@ } @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Signed val) { + return equal((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Unsigned val) { + return equal((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(int val) { + return equal(intParam(val)); + } + + @Operation(opcode = Opcode.COMPARISON, condition = Condition.EQ) + public boolean equal(Word val) { + return unbox() == val.unbox(); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Signed val) { + return notEqual((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Unsigned val) { + return notEqual((Word) val); + } + + @Override + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(int val) { + return notEqual(intParam(val)); + } + + @Operation(opcode = Opcode.COMPARISON, condition = Condition.NE) + public boolean notEqual(Word val) { + return unbox() != val.unbox(); + } + + @Override @Operation(opcode = Opcode.COMPARISON, condition = Condition.LT) public boolean lessThan(Signed val) { return lessThan((Word) val); @@ -815,6 +861,16 @@ public void writeObject(int offset, Object val) { writeObject(signed(offset), val); } + + @Override + public final boolean equals(Object obj) { + throw GraalInternalError.shouldNotReachHere("equals must not be called on words"); + } + + @Override + public final int hashCode() { + throw GraalInternalError.shouldNotReachHere("hashCode must not be called on words"); + } } final class HostedWord extends Word { @@ -823,7 +879,6 @@ private static final int SMALL_TO = 100; private static final HostedWord[] smallCache = new HostedWord[SMALL_TO - SMALL_FROM + 1]; - private static final ConcurrentHashMap cache = new ConcurrentHashMap<>(); static { for (int i = SMALL_FROM; i <= SMALL_TO; i++) { @@ -841,14 +896,7 @@ if (val >= SMALL_FROM && val <= SMALL_TO) { return smallCache[(int) val - SMALL_FROM]; } - Long key = val; - HostedWord result = cache.get(key); - if (result != null) { - return result; - } - HostedWord newValue = new HostedWord(val); - HostedWord oldValue = cache.putIfAbsent(key, newValue); - return oldValue == null ? newValue : oldValue; + return new HostedWord(val); } @Override diff -r ec6dc1326b15 -r 14720c279875 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 Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Mon Feb 04 20:23:57 2013 +0100 @@ -95,12 +95,13 @@ if (x.kind() == wordKind || y.kind() == wordKind) { assert x.kind() == wordKind; assert y.kind() == wordKind; - graph.replaceFloating(objectEqualsNode, graph.unique(new IntegerEqualsNode(x, y))); + + // TODO Remove the whole iteration of ObjectEqualsNodes when we are sure that there + // is no more code where this triggers. + throw GraalInternalError.shouldNotReachHere("Comparison of words with == and != is no longer supported"); } } - // Replace ObjectEqualsNodes with IntegerEqualsNodes where the values being compared are - // words for (LoadIndexedNode load : graph.getNodes().filter(LoadIndexedNode.class).snapshot()) { if (isWord(load)) { load.setStamp(StampFactory.forKind(wordKind)); diff -r ec6dc1326b15 -r 14720c279875 graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java Mon Feb 04 20:18:55 2013 +0100 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeVerificationPhase.java Mon Feb 04 20:23:57 2013 +0100 @@ -97,10 +97,8 @@ } } } else if (usage instanceof ObjectEqualsNode) { - ObjectEqualsNode compare = (ObjectEqualsNode) usage; - if (compare.x() == node || compare.y() == node) { - verify(isWord(compare.x()) == isWord(compare.y()), node, compare.usages().first(), "cannot mixed word and non-word type in use of '==' or '!='"); - } + verify(!isWord(node) || ((ObjectEqualsNode) usage).x() != node, node, usage, "cannot use word type in comparison"); + verify(!isWord(node) || ((ObjectEqualsNode) usage).y() != node, node, usage, "cannot use word type in comparison"); } else if (usage instanceof ArrayLengthNode) { verify(!isWord(node) || ((ArrayLengthNode) usage).array() != node, node, usage, "cannot get array length from word value"); } else if (usage instanceof PhiNode) { @@ -148,7 +146,7 @@ return buf.toString(); } else { String loc = GraphUtil.approxSourceLocation(n); - return loc == null ? "" : loc; + return loc == null ? MetaUtil.format("method %h.%n", ((StructuredGraph) n.graph()).method()) : loc; } } } diff -r ec6dc1326b15 -r 14720c279875 mx/projects --- a/mx/projects Mon Feb 04 20:18:55 2013 +0100 +++ b/mx/projects Mon Feb 04 20:23:57 2013 +0100 @@ -55,13 +55,6 @@ project@com.oracle.graal.api.code@checkstyle=com.oracle.graal.graph project@com.oracle.graal.api.code@javaCompliance=1.7 -# graal.api.interpreter -project@com.oracle.graal.api.interpreter@subDir=graal -project@com.oracle.graal.api.interpreter@sourceDirs=src -project@com.oracle.graal.api.interpreter@dependencies=com.oracle.graal.api.meta -project@com.oracle.graal.api.interpreter@checkstyle=com.oracle.graal.graph -project@com.oracle.graal.api.interpreter@javaCompliance=1.7 - # graal.amd64 project@com.oracle.graal.amd64@subDir=graal project@com.oracle.graal.amd64@sourceDirs=src @@ -72,7 +65,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.snippets,com.oracle.graal.api.interpreter,com.oracle.graal.api.runtime,com.oracle.graal.printer +project@com.oracle.graal.hotspot@dependencies=com.oracle.graal.snippets,com.oracle.graal.api.runtime,com.oracle.graal.printer project@com.oracle.graal.hotspot@checkstyle=com.oracle.graal.graph project@com.oracle.graal.hotspot@javaCompliance=1.7 @@ -165,13 +158,6 @@ project@com.oracle.graal.nodes@checkstyle=com.oracle.graal.graph project@com.oracle.graal.nodes@javaCompliance=1.7 -# graal.interpreter -project@com.oracle.graal.interpreter@subDir=graal -project@com.oracle.graal.interpreter@sourceDirs=src -project@com.oracle.graal.interpreter@dependencies=com.oracle.graal.api.interpreter,com.oracle.graal.bytecode,com.oracle.graal.api.runtime -project@com.oracle.graal.interpreter@checkstyle=com.oracle.graal.graph -project@com.oracle.graal.interpreter@javaCompliance=1.7 - # graal.phases project@com.oracle.graal.phases@subDir=graal project@com.oracle.graal.phases@sourceDirs=src diff -r ec6dc1326b15 -r 14720c279875 src/os/windows/vm/os_windows.cpp --- a/src/os/windows/vm/os_windows.cpp Mon Feb 04 20:18:55 2013 +0100 +++ b/src/os/windows/vm/os_windows.cpp Mon Feb 04 20:23:57 2013 +0100 @@ -2103,18 +2103,32 @@ #ifdef _M_IA64 assert(0, "Fix Handle_IDiv_Exception"); #elif _M_AMD64 - PCONTEXT ctx = exceptionInfo->ContextRecord; - address pc = (address)ctx->Rip; -#ifndef GRAAL - assert(pc[0] == 0xF7, "not an idiv opcode"); - assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); - assert(ctx->Rax == min_jint, "unexpected idiv exception"); -#endif - // set correct result values and continue after idiv instruction - ctx->Rip = (DWORD)pc + 2; // idiv reg, reg is 2 bytes - ctx->Rax = (DWORD)min_jint; // result - ctx->Rdx = (DWORD)0; // remainder - // Continue the execution + #ifdef GRAAL + PCONTEXT ctx = exceptionInfo->ContextRecord; + address pc = (address)ctx->Rip; + assert(pc[0] == 0x48 && pc[1] == 0xF7 || pc[0] == 0xF7, "not an idiv opcode"); + if (pc[0] == 0x48) { + // set correct result values and continue after idiv instruction + ctx->Rip = (DWORD64)pc + 3; // REX idiv reg, reg is 3 bytes + ctx->Rax = (DWORD64)min_jlong; // result + } else { + ctx->Rip = (DWORD64)pc + 2; // idiv reg, reg is 2 bytes + ctx->Rax = (DWORD64)min_jint; // result + } + ctx->Rdx = (DWORD64)0; // remainder + // Continue the execution + #else + PCONTEXT ctx = exceptionInfo->ContextRecord; + address pc = (address)ctx->Rip; + assert(pc[0] == 0xF7, "not an idiv opcode"); + assert((pc[1] & ~0x7) == 0xF8, "cannot handle non-register operands"); + assert(ctx->Rax == min_jint, "unexpected idiv exception"); + // set correct result values and continue after idiv instruction + ctx->Rip = (DWORD)pc + 2; // idiv reg, reg is 2 bytes + ctx->Rax = (DWORD)min_jint; // result + ctx->Rdx = (DWORD)0; // remainder + // Continue the execution + #endif // GRAAL #else PCONTEXT ctx = exceptionInfo->ContextRecord; address pc = (address)ctx->Eip; diff -r ec6dc1326b15 -r 14720c279875 src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp Mon Feb 04 20:18:55 2013 +0100 +++ b/src/share/vm/code/nmethod.cpp Mon Feb 04 20:23:57 2013 +0100 @@ -595,7 +595,7 @@ { assert(debug_info->oop_recorder() == code_buffer->oop_recorder(), "shared OR"); code_buffer->finalize_oop_references(method); - size_t leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); + int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); // create nmethod nmethod* nm = NULL; { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); @@ -911,7 +911,7 @@ _unwind_handler_offset = -1; } - size_t leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); + int leaf_graph_ids_size = leaf_graph_ids == NULL ? 0 : round_to(sizeof(jlong) * leaf_graph_ids->length(), oopSize); _oops_offset = data_offset(); _metadata_offset = _oops_offset + round_to(code_buffer->total_oop_size(), oopSize); diff -r ec6dc1326b15 -r 14720c279875 src/share/vm/runtime/arguments.cpp --- a/src/share/vm/runtime/arguments.cpp Mon Feb 04 20:18:55 2013 +0100 +++ b/src/share/vm/runtime/arguments.cpp Mon Feb 04 20:23:57 2013 +0100 @@ -2270,7 +2270,6 @@ "com.oracle.graal.api.runtime", "com.oracle.graal.api.meta", "com.oracle.graal.api.code", - "com.oracle.graal.api.interpreter", "com.oracle.graal.hotspot", "com.oracle.graal.asm", "com.oracle.graal.alloc", diff -r ec6dc1326b15 -r 14720c279875 src/share/vm/runtime/compilationPolicy.cpp --- a/src/share/vm/runtime/compilationPolicy.cpp Mon Feb 04 20:18:55 2013 +0100 +++ b/src/share/vm/runtime/compilationPolicy.cpp Mon Feb 04 20:23:57 2013 +0100 @@ -492,7 +492,7 @@ int hot_count = m->backedge_count(); const char* comment = "backedge_count"; - if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m)) { + if (is_compilation_enabled() && !m->is_not_osr_compilable() && can_be_compiled(m) && !m->queued_for_compilation() && m->code() == NULL) { if (TraceCompilationPolicy) { tty->print("backedge invocation trigger: "); m->print_short_name(tty); diff -r ec6dc1326b15 -r 14720c279875 src/share/vm/runtime/java.cpp --- a/src/share/vm/runtime/java.cpp Mon Feb 04 20:18:55 2013 +0100 +++ b/src/share/vm/runtime/java.cpp Mon Feb 04 20:23:57 2013 +0100 @@ -375,6 +375,10 @@ CompileBroker::print_times(); } + if(PrintNMethodStatistics) { + nmethod::print_statistics(); + } + if (PrintCodeCache) { MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); CodeCache::print();