# HG changeset patch # User Gilles Duboscq # Date 1389281372 -3600 # Node ID be5006687c43ec5f2ebd229db81e05035c73f5c2 # Parent 37b14ac9c5fb63a4c2f8b889d68a456f7ed9a6c4 Add initialization checks to Unsafe.allocateInstance intrinsic diff -r 37b14ac9c5fb -r be5006687c43 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Thu Jan 09 15:11:34 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/HotSpotReplacementsUtil.java Thu Jan 09 16:29:32 2014 +0100 @@ -24,7 +24,7 @@ import static com.oracle.graal.graph.UnsafeAccess.*; import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*; -import static com.oracle.graal.hotspot.meta.HotSpotHostForeignCallsProvider.*; +import static com.oracle.graal.hotspot.meta.HotSpotForeignCallsProviderImpl.*; import static com.oracle.graal.nodes.extended.BranchProbabilityNode.*; import sun.misc.*; @@ -506,6 +506,14 @@ return config().klassStateFullyInitialized; } + public static boolean isKlassFullyInitialized(Word hub) { + return readKlassState(hub) == klassStateFullyInitialized(); + } + + public static byte readKlassState(Word hub) { + return hub.readByte(klassStateOffset(), CLASS_STATE_LOCATION); + } + @Fold public static int klassModifierFlagsOffset() { return config().klassModifierFlagsOffset; diff -r 37b14ac9c5fb -r be5006687c43 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Thu Jan 09 15:11:34 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Thu Jan 09 16:29:32 2014 +0100 @@ -152,16 +152,18 @@ public static Object allocateInstanceDynamic(Class type, @ConstantParameter boolean fillContents, @ConstantParameter Register threadRegister, @ConstantParameter String typeContext) { Word hub = loadWordFromObject(type, klassOffset()); if (!hub.equal(Word.zero())) { - int layoutHelper = readLayoutHelper(hub); - /* - * src/share/vm/oops/klass.hpp: For instances, layout helper is a positive number, the - * instance size. This size is already passed through align_object_size and scaled to - * bytes. The low order bit is set if instances of this class cannot be allocated using - * the fastpath. - */ - if ((layoutHelper & 1) == 0) { - Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION); - return allocateInstance(layoutHelper, hub, prototypeMarkWord, fillContents, threadRegister, false, typeContext); + if (isKlassFullyInitialized(hub)) { + int layoutHelper = readLayoutHelper(hub); + /* + * src/share/vm/oops/klass.hpp: For instances, layout helper is a positive number, + * the instance size. This size is already passed through align_object_size and + * scaled to bytes. The low order bit is set if instances of this class cannot be + * allocated using the fastpath. + */ + if ((layoutHelper & 1) == 0) { + Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION); + return allocateInstance(layoutHelper, hub, prototypeMarkWord, fillContents, threadRegister, false, typeContext); + } } } return dynamicNewInstanceStub(type); diff -r 37b14ac9c5fb -r be5006687c43 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Thu Jan 09 15:11:34 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/NewInstanceStub.java Thu Jan 09 16:29:32 2014 +0100 @@ -107,7 +107,7 @@ int sizeInBytes = hub.readInt(klassInstanceSizeOffset(), LocationIdentity.FINAL_LOCATION); Word thread = registerAsWord(threadRegister); if (!forceSlowPath() && inlineContiguousAllocationSupported()) { - if (hub.readByte(klassStateOffset(), CLASS_STATE_LOCATION) == klassStateFullyInitialized()) { + if (isKlassFullyInitialized(hub)) { Word memory = refillAllocate(thread, intArrayHub, sizeInBytes, logging()); if (memory.notEqual(0)) { Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION); diff -r 37b14ac9c5fb -r be5006687c43 graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java --- a/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java Thu Jan 09 15:11:34 2014 +0100 +++ b/graal/com.oracle.graal.jtt/src/com/oracle/graal/jtt/jdk/UnsafeAllocateInstance01.java Thu Jan 09 16:29:32 2014 +0100 @@ -35,10 +35,6 @@ */ public class UnsafeAllocateInstance01 extends JTTTest { - private static abstract class AbstractClass { - - } - int field01 = 42; public static int testInstance() throws SecurityException, InstantiationException { @@ -79,7 +75,7 @@ @Test public void run2() throws Throwable { - runTest("testClassForException", AbstractClass.class); + runTest("testClassForException", AbstractList.class); } @Test diff -r 37b14ac9c5fb -r be5006687c43 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewInstanceNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewInstanceNode.java Thu Jan 09 15:11:34 2014 +0100 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/java/DynamicNewInstanceNode.java Thu Jan 09 16:29:32 2014 +0100 @@ -44,7 +44,9 @@ if (clazzConstant.getKind() == Kind.Object && clazzConstant.asObject() instanceof Class) { Class staticClass = (Class) clazzConstant.asObject(); ResolvedJavaType type = tool.getMetaAccess().lookupJavaType(staticClass); - return new NewInstanceNode(type, fillContents()); + if (type.isInitialized()) { + return new NewInstanceNode(type, fillContents()); + } } } return super.canonical(tool);