# HG changeset patch # User Roland Schatz # Date 1416838009 -3600 # Node ID 8d9c1a018e77eb8c4d4f365aced79f4905ab112d # Parent ca81508f2a197053a48defd02ee9b3e6e1c3c4e7 Introduce isNull() method for metaspace pointers. diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/ClassSubstitutions.java Mon Nov 24 15:06:49 2014 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2014, 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 @@ -57,11 +57,11 @@ @MacroSubstitution(macro = ClassIsInterfaceNode.class, isStatic = false) @MethodSubstitution(isStatic = false, forced = true) public static boolean isInterface(final Class thisObj) { - Pointer klass = ClassGetHubNode.readClass(thisObj).asWord(); - if (klass.equal(0)) { + KlassPointer klass = ClassGetHubNode.readClass(thisObj); + if (klass.isNull()) { return false; } else { - int accessFlags = klass.readInt(klassAccessFlagsOffset(), KLASS_ACCESS_FLAGS_LOCATION); + int accessFlags = klass.asWord().readInt(klassAccessFlagsOffset(), KLASS_ACCESS_FLAGS_LOCATION); return (accessFlags & Modifier.INTERFACE) != 0; } } @@ -70,12 +70,11 @@ @MacroSubstitution(macro = ClassIsArrayNode.class, isStatic = false) @MethodSubstitution(isStatic = false, forced = true) public static boolean isArray(final Class thisObj) { - KlassPointer klassPtr = ClassGetHubNode.readClass(thisObj); - Pointer klass = klassPtr.asWord(); - if (klass.equal(0)) { + KlassPointer klass = ClassGetHubNode.readClass(thisObj); + if (klass.isNull()) { return false; } else { - return klassIsArray(klassPtr); + return klassIsArray(klass); } } @@ -83,8 +82,8 @@ @MacroSubstitution(macro = ClassIsPrimitiveNode.class, isStatic = false) @MethodSubstitution(isStatic = false, forced = true) public static boolean isPrimitive(final Class thisObj) { - Pointer klass = ClassGetHubNode.readClass(thisObj).asWord(); - return klass.equal(0); + KlassPointer klass = ClassGetHubNode.readClass(thisObj); + return klass.isNull(); } @MacroSubstitution(macro = ClassGetClassLoader0Node.class, isStatic = false) @@ -94,8 +93,8 @@ @MethodSubstitution(isStatic = false) public static Class getSuperclass(final Class thisObj) { KlassPointer klassPtr = ClassGetHubNode.readClass(thisObj); - Pointer klass = klassPtr.asWord(); - if (klass.notEqual(0)) { + if (!klassPtr.isNull()) { + Pointer klass = klassPtr.asWord(); int accessFlags = klass.readInt(klassAccessFlagsOffset(), KLASS_ACCESS_FLAGS_LOCATION); if ((accessFlags & Modifier.INTERFACE) == 0) { if (klassIsArray(klassPtr)) { @@ -116,11 +115,10 @@ @MacroSubstitution(macro = ClassGetComponentTypeNode.class, isStatic = false) @MethodSubstitution(isStatic = false) public static Class getComponentType(final Class thisObj) { - KlassPointer klassPtr = ClassGetHubNode.readClass(thisObj); - Pointer klass = klassPtr.asWord(); - if (klass.notEqual(0)) { - if (klassIsArray(klassPtr)) { - return piCastExactNonNull(klass.readObject(arrayKlassComponentMirrorOffset(), ARRAY_KLASS_COMPONENT_MIRROR), Class.class); + KlassPointer klass = ClassGetHubNode.readClass(thisObj); + if (!klass.isNull()) { + if (klassIsArray(klass)) { + return piCastExactNonNull(klass.asWord().readObject(arrayKlassComponentMirrorOffset(), ARRAY_KLASS_COMPONENT_MIRROR), Class.class); } } return null; diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/InstanceOfSnippets.java Mon Nov 24 15:06:49 2014 +0100 @@ -161,18 +161,18 @@ return falseValue; } GuardingNode anchorNode = SnippetAnchorNode.anchor(); - Pointer objectHub = loadHubIntrinsic(object, anchorNode).asWord(); + KlassPointer objectHub = loadHubIntrinsic(object, anchorNode); // if we get an exact match: succeed immediately ExplodeLoopNode.explodeLoop(); for (int i = 0; i < hints.length; i++) { - Pointer hintHub = hints[i].asWord(); + KlassPointer hintHub = hints[i]; boolean positive = hintIsPositive[i]; if (probability(NOT_FREQUENT_PROBABILITY, hintHub.equal(objectHub))) { hintsHit.inc(); return positive ? trueValue : falseValue; } } - if (!checkSecondarySubType(hub.asWord(), objectHub)) { + if (!checkSecondarySubType(hub.asWord(), objectHub.asWord())) { return falseValue; } return trueValue; @@ -188,9 +188,9 @@ return falseValue; } GuardingNode anchorNode = SnippetAnchorNode.anchor(); - Pointer hub = ClassGetHubNode.readClass(mirror, anchorNode).asWord(); - Pointer objectHub = loadHubIntrinsic(object, anchorNode).asWord(); - if (hub.equal(0) || !checkUnknownSubType(hub, objectHub)) { + KlassPointer hub = ClassGetHubNode.readClass(mirror, anchorNode); + KlassPointer objectHub = loadHubIntrinsic(object, anchorNode); + if (hub.isNull() || !checkUnknownSubType(hub.asWord(), objectHub.asWord())) { return falseValue; } return trueValue; diff -r ca81508f2a19 -r 8d9c1a018e77 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 Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Mon Nov 24 15:06:49 2014 +0100 @@ -154,8 +154,8 @@ @Snippet public static Object allocateInstanceDynamic(Class type, @ConstantParameter boolean fillContents, @ConstantParameter Register threadRegister, @ConstantParameter String typeContext) { KlassPointer hubPtr = ClassGetHubNode.readClass(type); - Pointer hub = hubPtr.asWord(); - if (probability(FAST_PATH_PROBABILITY, !hub.equal(Word.zero()))) { + if (probability(FAST_PATH_PROBABILITY, !hubPtr.isNull())) { + Pointer hub = hubPtr.asWord(); if (probability(FAST_PATH_PROBABILITY, isInstanceKlassFullyInitialized(hub))) { int layoutHelper = readLayoutHelper(hubPtr); /* diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/StubUtil.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/StubUtil.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/stubs/StubUtil.java Mon Nov 24 15:06:49 2014 +0100 @@ -36,6 +36,7 @@ import com.oracle.graal.graph.Node.ConstantNodeParameter; import com.oracle.graal.graph.Node.NodeIntrinsic; import com.oracle.graal.hotspot.nodes.*; +import com.oracle.graal.hotspot.word.*; import com.oracle.graal.nodes.extended.*; import com.oracle.graal.replacements.*; import com.oracle.graal.word.*; @@ -229,8 +230,8 @@ fatal("oop not in heap: %p", oop.rawValue()); } - Pointer klass = loadHubIntrinsic(object, anchorNode).asWord(); - if (klass.equal(Word.zero())) { + KlassPointer klass = loadHubIntrinsic(object, anchorNode); + if (klass.isNull()) { fatal("klass for oop %p is null", oop.rawValue()); } } diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotOperation.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotOperation.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotOperation.java Mon Nov 24 15:06:49 2014 +0100 @@ -33,7 +33,8 @@ TO_KLASS_POINTER, TO_METHOD_POINTER, POINTER_EQ, - POINTER_NE + POINTER_NE, + IS_NULL } HotspotOpcode opcode(); diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotWordTypeRewriterPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotWordTypeRewriterPhase.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/HotSpotWordTypeRewriterPhase.java Mon Nov 24 15:06:49 2014 +0100 @@ -100,6 +100,11 @@ replace(invoke, pointerComparisonOp(graph, operation.opcode(), arguments.get(0), arguments.get(1))); break; + case IS_NULL: + assert arguments.size() == 1; + replace(invoke, pointerIsNullOp(graph, arguments.get(0))); + break; + case FROM_POINTER: assert arguments.size() == 1; replace(invoke, graph.unique(PointerCastNode.create(StampFactory.forKind(wordKind), arguments.get(0)))); @@ -130,4 +135,11 @@ ValueNode neValue = ConstantNode.forBoolean(opcode == POINTER_NE, graph); return graph.unique(ConditionalNode.create(comparison, eqValue, neValue)); } + + private static ValueNode pointerIsNullOp(StructuredGraph graph, ValueNode pointer) { + assert pointer.stamp() instanceof MetaspacePointerStamp; + + IsNullNode isNull = graph.unique(IsNullNode.create(pointer)); + return graph.unique(ConditionalNode.create(isNull, ConstantNode.forBoolean(true, graph), ConstantNode.forBoolean(false, graph))); + } } diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/KlassPointer.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/KlassPointer.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/KlassPointer.java Mon Nov 24 15:06:49 2014 +0100 @@ -29,7 +29,7 @@ /** * Marker type for a metaspace pointer to a type. */ -public abstract class KlassPointer { +public abstract class KlassPointer extends MetaspacePointer { @HotSpotOperation(opcode = POINTER_EQ) public abstract boolean equal(KlassPointer other); @@ -37,9 +37,6 @@ @HotSpotOperation(opcode = POINTER_NE) public abstract boolean notEqual(KlassPointer other); - @HotSpotOperation(opcode = FROM_POINTER) - public abstract Pointer asWord(); - @HotSpotOperation(opcode = TO_KLASS_POINTER) public static native KlassPointer fromWord(Pointer pointer); } diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/MetaspacePointer.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/MetaspacePointer.java Mon Nov 24 15:06:49 2014 +0100 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.graal.hotspot.word; + +import static com.oracle.graal.hotspot.word.HotSpotOperation.HotspotOpcode.*; + +import com.oracle.graal.word.*; + +/** + * Marker type for a metaspace pointer. + */ +public abstract class MetaspacePointer { + + @HotSpotOperation(opcode = IS_NULL) + public abstract boolean isNull(); + + @HotSpotOperation(opcode = FROM_POINTER) + public abstract Pointer asWord(); +} diff -r ca81508f2a19 -r 8d9c1a018e77 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/MethodPointer.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/MethodPointer.java Mon Nov 24 13:53:14 2014 +0100 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/word/MethodPointer.java Mon Nov 24 15:06:49 2014 +0100 @@ -29,7 +29,7 @@ /** * Marker type for a metaspace pointer to a method. */ -public abstract class MethodPointer { +public abstract class MethodPointer extends MetaspacePointer { @HotSpotOperation(opcode = POINTER_EQ) public abstract boolean equal(KlassPointer other); @@ -37,9 +37,6 @@ @HotSpotOperation(opcode = POINTER_NE) public abstract boolean notEqual(KlassPointer other); - @HotSpotOperation(opcode = FROM_POINTER) - public abstract Pointer asWord(); - @HotSpotOperation(opcode = TO_METHOD_POINTER) public static native MethodPointer fromWord(Pointer pointer); }