# HG changeset patch # User Roland Schatz # Date 1429203145 -7200 # Node ID 59e8737c06fd44e0121583e60f99651bc541da61 # Parent 68ff637e95b1059f52c0c7c9c721ea8a6a4bf120 Fix bug in LoadJavaMirrorWithKlassPhase. diff -r 68ff637e95b1 -r 59e8737c06fd graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/LoadJavaMirrorWithKlassTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/LoadJavaMirrorWithKlassTest.java Thu Apr 16 18:52:25 2015 +0200 @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2015, 2015, 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.test; + +import java.util.*; + +import org.junit.*; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.compiler.common.*; +import com.oracle.graal.compiler.test.*; +import com.oracle.graal.nodes.*; +import com.oracle.graal.options.*; +import com.oracle.graal.options.OptionValue.OverrideScope; +import com.oracle.graal.phases.tiers.*; + +public class LoadJavaMirrorWithKlassTest extends GraalCompilerTest { + + private static class Wrapper { + private Class clazz; + + @Override + public boolean equals(Object obj) { + if (obj instanceof Wrapper) { + return Objects.equals(this.clazz, ((Wrapper) obj).clazz); + } else { + return false; + } + } + + @Override + public int hashCode() { + return clazz.hashCode(); + } + } + + @Override + protected Suites createSuites() { + try (OverrideScope s = OptionValue.override(GraalOptions.ImmutableCode, true)) { + return super.createSuites(); + } + } + + @Override + protected boolean checkLowTierGraph(StructuredGraph graph) { + for (ConstantNode constantNode : graph.getNodes().filter(ConstantNode.class)) { + assert constantNode.asJavaConstant() == null || constantNode.asJavaConstant().getKind() != Kind.Object : "Found unexpected object constant " + constantNode + + ", this should have been removed by the LoadJavaMirrorWithKlassPhase."; + } + return true; + } + + public static Class classConstant() { + return Wrapper.class; + } + + @Test + public void testClassConstant() { + test("classConstant"); + } + + public static Class primitiveClassConstant() { + return int.class; + } + + @Test + public void testPrimitiveClassConstant() { + test("primitiveClassConstant"); + } + + public static Wrapper compressedClassConstant(Wrapper w) { + w.clazz = Wrapper.class; + return w; + } + + @Test + public void testCompressedClassConstant() { + ArgSupplier arg = () -> new Wrapper(); + test("compressedClassConstant", arg); + } + + public static Wrapper compressedPrimitiveClassConstant(Wrapper w) { + w.clazz = int.class; + return w; + } + + @Test + public void testCompressedPrimitiveClassConstant() { + ArgSupplier arg = () -> new Wrapper(); + test("compressedPrimitiveClassConstant", arg); + } +} diff -r 68ff637e95b1 -r 59e8737c06fd graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Thu Apr 16 17:09:06 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotSuitesProvider.java Thu Apr 16 18:52:25 2015 +0200 @@ -86,7 +86,7 @@ if (ImmutableCode.getValue()) { // lowering introduces class constants, therefore it must be after lowering - ret.getHighTier().appendPhase(new LoadJavaMirrorWithKlassPhase(runtime.getConfig().classMirrorOffset, runtime.getConfig().getOopEncoding())); + ret.getHighTier().appendPhase(new LoadJavaMirrorWithKlassPhase(runtime.getConfig().classMirrorOffset, runtime.getConfig().useCompressedOops ? runtime.getConfig().getOopEncoding() : null)); if (VerifyPhases.getValue()) { ret.getHighTier().appendPhase(new AheadOfTimeVerificationPhase()); } diff -r 68ff637e95b1 -r 59e8737c06fd graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java Thu Apr 16 17:09:06 2015 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/phases/LoadJavaMirrorWithKlassPhase.java Thu Apr 16 18:52:25 2015 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 @@ -63,15 +63,21 @@ private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) { if (constant instanceof HotSpotObjectConstant) { ConstantReflectionProvider constantReflection = context.getConstantReflection(); - ResolvedJavaType c = constantReflection.asJavaType(constant); - if (c != null) { + ResolvedJavaType type = constantReflection.asJavaType(constant); + if (type != null) { MetaAccessProvider metaAccess = context.getMetaAccess(); - ResolvedJavaType type = c; - Constant klass; - LocationNode location; + Stamp stamp = StampFactory.exactNonNull(metaAccess.lookupJavaType(Class.class)); + if (type instanceof HotSpotResolvedObjectType) { - location = graph.unique(new ConstantLocationNode(CLASS_MIRROR_LOCATION, classMirrorOffset)); - klass = ((HotSpotResolvedObjectType) type).klass(); + ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph); + LocationNode location = graph.unique(new ConstantLocationNode(CLASS_MIRROR_LOCATION, classMirrorOffset)); + ValueNode read = graph.unique(new FloatingReadNode(klass, location, null, stamp)); + + if (((HotSpotObjectConstant) constant).isCompressed()) { + return CompressionNode.compress(read, oopEncoding); + } else { + return read; + } } else { /* * Primitive classes are more difficult since they don't have a corresponding @@ -79,7 +85,7 @@ */ HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type; ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getKind().toBoxedJavaClass()); - klass = ((HotSpotResolvedObjectType) boxingClass).klass(); + ConstantNode clazz = ConstantNode.forConstant(boxingClass.getJavaClass(), metaAccess, graph); HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields(); HotSpotResolvedJavaField typeField = null; for (HotSpotResolvedJavaField f : a) { @@ -91,17 +97,18 @@ if (typeField == null) { throw new GraalInternalError("Can't find TYPE field in class"); } - location = graph.unique(new ConstantLocationNode(FINAL_LOCATION, typeField.offset())); - } - ConstantNode klassNode = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), klass, metaAccess, graph); - Stamp stamp = StampFactory.exactNonNull(metaAccess.lookupJavaType(Class.class)); - FloatingReadNode freadNode = graph.unique(new FloatingReadNode(klassNode, location, null, stamp)); + LocationNode location = graph.unique(new ConstantLocationNode(FINAL_LOCATION, typeField.offset())); + if (oopEncoding != null) { + stamp = NarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding); + } + ValueNode read = graph.unique(new FloatingReadNode(clazz, location, null, stamp)); - if (((HotSpotObjectConstant) constant).isCompressed()) { - return CompressionNode.compress(freadNode, oopEncoding); - } else { - return freadNode; + if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) { + return read; + } else { + return CompressionNode.uncompress(read, oopEncoding); + } } } }