1 /*
   2  * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.hotspot.meta;
  24 
  25 import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntimeProvider.getArrayBaseOffset;
  26 import static org.graalvm.compiler.core.common.GraalOptions.AlwaysInlineVTableStubs;
  27 import static org.graalvm.compiler.core.common.GraalOptions.InlineVTableStubs;
  28 import static org.graalvm.compiler.core.common.GraalOptions.OmitHotExceptionStacktrace;
  29 import static org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl.OSR_MIGRATION_END;
  30 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_KLASS_LOCATION;
  31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_LOCATION;
  32 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_HANDLE_LOCATION;

  33 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.COMPRESSED_HUB_LOCATION;
  34 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.DISPLACED_MARK_WORD_LOCATION;
  35 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_LOCATION;
  36 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_WRITE_LOCATION;
  37 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_LAYOUT_HELPER_LOCATION;
  38 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION;
  39 import static org.graalvm.word.LocationIdentity.any;
  40 
  41 import java.lang.ref.Reference;
  42 
  43 import org.graalvm.compiler.api.directives.GraalDirectives;

  44 import org.graalvm.compiler.core.common.GraalOptions;
  45 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  46 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  47 import org.graalvm.compiler.core.common.type.ObjectStamp;
  48 import org.graalvm.compiler.core.common.type.Stamp;
  49 import org.graalvm.compiler.core.common.type.StampFactory;
  50 import org.graalvm.compiler.core.common.type.StampPair;
  51 import org.graalvm.compiler.debug.DebugHandlersFactory;
  52 import org.graalvm.compiler.debug.GraalError;
  53 import org.graalvm.compiler.graph.Node;
  54 import org.graalvm.compiler.graph.NodeInputList;
  55 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  56 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  57 import org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode;
  58 import org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode;
  59 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier;
  60 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier;
  61 import org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier;
  62 import org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier;
  63 import org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier;
  64 import org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode;
  65 import org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode;
  66 import org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode;
  67 import org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode;
  68 import org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier;
  69 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
  70 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
  71 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
  72 import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
  73 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
  74 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  75 import org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp;
  76 import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp;
  77 import org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp;
  78 import org.graalvm.compiler.hotspot.replacements.AssertionSnippets;
  79 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  80 import org.graalvm.compiler.hotspot.replacements.HashCodeSnippets;
  81 import org.graalvm.compiler.hotspot.replacements.HubGetClassNode;
  82 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  83 import org.graalvm.compiler.hotspot.replacements.InstanceOfSnippets;
  84 import org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode;
  85 import org.graalvm.compiler.hotspot.replacements.LoadExceptionObjectSnippets;
  86 import org.graalvm.compiler.hotspot.replacements.MonitorSnippets;
  87 import org.graalvm.compiler.hotspot.replacements.NewObjectSnippets;
  88 import org.graalvm.compiler.hotspot.replacements.StringToBytesSnippets;
  89 import org.graalvm.compiler.hotspot.replacements.UnsafeLoadSnippets;
  90 import org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets;
  91 import org.graalvm.compiler.hotspot.replacements.aot.ResolveConstantSnippets;
  92 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyNode;
  93 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopySlowPathNode;
  94 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopySnippets;
  95 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyUnrollNode;
  96 import org.graalvm.compiler.hotspot.replacements.arraycopy.UnsafeArrayCopySnippets;
  97 import org.graalvm.compiler.hotspot.replacements.profiling.ProfileSnippets;
  98 import org.graalvm.compiler.hotspot.word.KlassPointer;
  99 import org.graalvm.compiler.nodes.AbstractBeginNode;
 100 import org.graalvm.compiler.nodes.AbstractDeoptimizeNode;
 101 import org.graalvm.compiler.nodes.CompressionNode.CompressionOp;
 102 import org.graalvm.compiler.nodes.ConstantNode;
 103 import org.graalvm.compiler.nodes.FixedNode;
 104 import org.graalvm.compiler.nodes.Invoke;
 105 import org.graalvm.compiler.nodes.LogicNode;
 106 import org.graalvm.compiler.nodes.LoweredCallTargetNode;
 107 import org.graalvm.compiler.nodes.ParameterNode;
 108 import org.graalvm.compiler.nodes.SafepointNode;
 109 import org.graalvm.compiler.nodes.StartNode;
 110 import org.graalvm.compiler.nodes.StructuredGraph;
 111 import org.graalvm.compiler.nodes.UnwindNode;
 112 import org.graalvm.compiler.nodes.ValueNode;
 113 import org.graalvm.compiler.nodes.calc.AddNode;
 114 import org.graalvm.compiler.nodes.calc.FloatingNode;
 115 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
 116 import org.graalvm.compiler.nodes.calc.IsNullNode;
 117 import org.graalvm.compiler.nodes.calc.RemNode;
 118 import org.graalvm.compiler.nodes.debug.StringToBytesNode;
 119 import org.graalvm.compiler.nodes.debug.VerifyHeapNode;
 120 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 121 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
 122 import org.graalvm.compiler.nodes.extended.GetClassNode;
 123 import org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode;
 124 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 125 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 126 import org.graalvm.compiler.nodes.extended.OSRLocalNode;
 127 import org.graalvm.compiler.nodes.extended.OSRLockNode;
 128 import org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode;
 129 import org.graalvm.compiler.nodes.extended.OSRStartNode;
 130 import org.graalvm.compiler.nodes.extended.RawLoadNode;
 131 import org.graalvm.compiler.nodes.extended.StoreHubNode;
 132 import org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode;
 133 import org.graalvm.compiler.nodes.java.DynamicNewArrayNode;
 134 import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode;
 135 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
 136 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 137 import org.graalvm.compiler.nodes.java.LoadExceptionObjectNode;
 138 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 139 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 140 import org.graalvm.compiler.nodes.java.MonitorIdNode;
 141 import org.graalvm.compiler.nodes.java.NewArrayNode;
 142 import org.graalvm.compiler.nodes.java.NewInstanceNode;
 143 import org.graalvm.compiler.nodes.java.NewMultiArrayNode;
 144 import org.graalvm.compiler.nodes.java.RawMonitorEnterNode;
 145 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
 146 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
 147 import org.graalvm.compiler.nodes.memory.ReadNode;
 148 import org.graalvm.compiler.nodes.memory.WriteNode;
 149 import org.graalvm.compiler.nodes.memory.address.AddressNode;
 150 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 151 import org.graalvm.compiler.nodes.spi.LoweringTool;
 152 import org.graalvm.compiler.nodes.spi.StampProvider;
 153 import org.graalvm.compiler.nodes.type.StampTool;
 154 import org.graalvm.compiler.nodes.util.GraphUtil;
 155 import org.graalvm.compiler.options.OptionValues;
 156 import org.graalvm.compiler.replacements.DefaultJavaLoweringProvider;
 157 import org.graalvm.compiler.replacements.nodes.AssertionNode;
 158 import org.graalvm.word.LocationIdentity;
 159 
 160 import jdk.vm.ci.code.TargetDescription;
 161 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
 162 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
 163 import jdk.vm.ci.hotspot.HotSpotResolvedJavaField;
 164 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 165 import jdk.vm.ci.meta.JavaConstant;
 166 import jdk.vm.ci.meta.JavaKind;
 167 import jdk.vm.ci.meta.JavaType;
 168 import jdk.vm.ci.meta.MetaAccessProvider;
 169 import jdk.vm.ci.meta.ResolvedJavaField;
 170 import jdk.vm.ci.meta.ResolvedJavaType;
 171 
 172 /**
 173  * HotSpot implementation of {@link LoweringProvider}.
 174  */
 175 public class DefaultHotSpotLoweringProvider extends DefaultJavaLoweringProvider implements HotSpotLoweringProvider {
 176 
 177     protected final HotSpotGraalRuntimeProvider runtime;
 178     protected final HotSpotRegistersProvider registers;
 179     protected final HotSpotConstantReflectionProvider constantReflection;
 180 
 181     protected InstanceOfSnippets.Templates instanceofSnippets;
 182     protected NewObjectSnippets.Templates newObjectSnippets;
 183     protected MonitorSnippets.Templates monitorSnippets;
 184     protected WriteBarrierSnippets.Templates writeBarrierSnippets;
 185     protected LoadExceptionObjectSnippets.Templates exceptionObjectSnippets;
 186     protected UnsafeLoadSnippets.Templates unsafeLoadSnippets;
 187     protected AssertionSnippets.Templates assertionSnippets;
 188     protected ArrayCopySnippets.Templates arraycopySnippets;
 189     protected StringToBytesSnippets.Templates stringToBytesSnippets;
 190     protected HashCodeSnippets.Templates hashCodeSnippets;
 191     protected ResolveConstantSnippets.Templates resolveConstantSnippets;
 192     protected ProfileSnippets.Templates profileSnippets;
 193 
 194     public DefaultHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
 195                     HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
 196         super(metaAccess, foreignCalls, target);
 197         this.runtime = runtime;
 198         this.registers = registers;
 199         this.constantReflection = constantReflection;
 200     }
 201 
 202     @Override
 203     public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
 204         super.initialize(options, factories, runtime, providers, providers.getSnippetReflection());
 205 
 206         assert target == providers.getCodeCache().getTarget();
 207         instanceofSnippets = new InstanceOfSnippets.Templates(options, factories, runtime, providers, target);
 208         newObjectSnippets = new NewObjectSnippets.Templates(options, factories, runtime, providers, target, config);
 209         monitorSnippets = new MonitorSnippets.Templates(options, factories, runtime, providers, target, config.useFastLocking);
 210         writeBarrierSnippets = new WriteBarrierSnippets.Templates(options, factories, runtime, providers, target, config.useCompressedOops ? config.getOopEncoding() : null);
 211         exceptionObjectSnippets = new LoadExceptionObjectSnippets.Templates(options, factories, providers, target);
 212         unsafeLoadSnippets = new UnsafeLoadSnippets.Templates(options, factories, providers, target);
 213         assertionSnippets = new AssertionSnippets.Templates(options, factories, providers, target);
 214         arraycopySnippets = new ArrayCopySnippets.Templates(options, factories, runtime, providers, target);
 215         stringToBytesSnippets = new StringToBytesSnippets.Templates(options, factories, providers, target);
 216         hashCodeSnippets = new HashCodeSnippets.Templates(options, factories, providers, target);
 217         resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
 218         profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);
 219         providers.getReplacements().registerSnippetTemplateCache(new UnsafeArrayCopySnippets.Templates(options, factories, providers, target));
 220     }
 221 
 222     public MonitorSnippets.Templates getMonitorSnippets() {
 223         return monitorSnippets;
 224     }
 225 
 226     @Override
 227     public void lower(Node n, LoweringTool tool) {
 228         StructuredGraph graph = (StructuredGraph) n.graph();
 229         if (n instanceof Invoke) {
 230             lowerInvoke((Invoke) n, tool, graph);
 231         } else if (n instanceof LoadMethodNode) {
 232             lowerLoadMethodNode((LoadMethodNode) n);
 233         } else if (n instanceof GetClassNode) {
 234             lowerGetClassNode((GetClassNode) n, tool, graph);
 235         } else if (n instanceof StoreHubNode) {
 236             lowerStoreHubNode((StoreHubNode) n, graph);
 237         } else if (n instanceof OSRStartNode) {
 238             lowerOSRStartNode((OSRStartNode) n);
 239         } else if (n instanceof BytecodeExceptionNode) {
 240             lowerBytecodeExceptionNode((BytecodeExceptionNode) n);
 241         } else if (n instanceof InstanceOfNode) {
 242             InstanceOfNode instanceOfNode = (InstanceOfNode) n;
 243             if (graph.getGuardsStage().areDeoptsFixed()) {
 244                 instanceofSnippets.lower(instanceOfNode, tool);
 245             } else {
 246                 if (instanceOfNode.allowsNull()) {
 247                     ValueNode object = instanceOfNode.getValue();
 248                     LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfNode.create(instanceOfNode.type(), object, instanceOfNode.profile(), instanceOfNode.getAnchor()));
 249                     LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 250                     instanceOfNode.replaceAndDelete(newNode);
 251                 }
 252             }
 253         } else if (n instanceof InstanceOfDynamicNode) {
 254             InstanceOfDynamicNode instanceOfDynamicNode = (InstanceOfDynamicNode) n;
 255             if (graph.getGuardsStage().areDeoptsFixed()) {
 256                 instanceofSnippets.lower(instanceOfDynamicNode, tool);
 257             } else {
 258                 ValueNode mirror = instanceOfDynamicNode.getMirrorOrHub();
 259                 if (mirror.stamp().getStackKind() == JavaKind.Object) {
 260                     ClassGetHubNode classGetHub = graph.unique(new ClassGetHubNode(mirror));
 261                     instanceOfDynamicNode.setMirror(classGetHub);
 262                 }
 263 
 264                 if (instanceOfDynamicNode.allowsNull()) {
 265                     ValueNode object = instanceOfDynamicNode.getObject();
 266                     LogicNode newTypeCheck = graph.addOrUniqueWithInputs(
 267                                     InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), instanceOfDynamicNode.getMirrorOrHub(), object, false));
 268                     LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 269                     instanceOfDynamicNode.replaceAndDelete(newNode);
 270                 }
 271             }
 272         } else if (n instanceof ClassIsAssignableFromNode) {
 273             if (graph.getGuardsStage().areDeoptsFixed()) {
 274                 instanceofSnippets.lower((ClassIsAssignableFromNode) n, tool);
 275             }
 276         } else if (n instanceof NewInstanceNode) {
 277             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 278                 newObjectSnippets.lower((NewInstanceNode) n, registers, tool);
 279             }
 280         } else if (n instanceof DynamicNewInstanceNode) {
 281             DynamicNewInstanceNode newInstanceNode = (DynamicNewInstanceNode) n;
 282             if (newInstanceNode.getClassClass() == null) {
 283                 JavaConstant classClassMirror = constantReflection.forObject(Class.class);
 284                 ConstantNode classClass = ConstantNode.forConstant(classClassMirror, tool.getMetaAccess(), graph);
 285                 newInstanceNode.setClassClass(classClass);
 286             }
 287             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 288                 newObjectSnippets.lower(newInstanceNode, registers, tool);
 289             }
 290         } else if (n instanceof NewArrayNode) {
 291             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 292                 newObjectSnippets.lower((NewArrayNode) n, registers, tool);
 293             }
 294         } else if (n instanceof DynamicNewArrayNode) {
 295             DynamicNewArrayNode dynamicNewArrayNode = (DynamicNewArrayNode) n;
 296             if (dynamicNewArrayNode.getVoidClass() == null) {
 297                 JavaConstant voidClassMirror = constantReflection.forObject(void.class);
 298                 ConstantNode voidClass = ConstantNode.forConstant(voidClassMirror, tool.getMetaAccess(), graph);
 299                 dynamicNewArrayNode.setVoidClass(voidClass);
 300             }
 301             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 302                 newObjectSnippets.lower(dynamicNewArrayNode, registers, tool);
 303             }
 304         } else if (n instanceof VerifyHeapNode) {
 305             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 306                 newObjectSnippets.lower((VerifyHeapNode) n, registers, tool);
 307             }
 308         } else if (n instanceof RawMonitorEnterNode) {
 309             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 310                 monitorSnippets.lower((RawMonitorEnterNode) n, registers, tool);
 311             }
 312         } else if (n instanceof MonitorExitNode) {
 313             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 314                 monitorSnippets.lower((MonitorExitNode) n, registers, tool);
 315             }
 316         } else if (n instanceof ArrayCopyNode) {
 317             arraycopySnippets.lower((ArrayCopyNode) n, tool);
 318         } else if (n instanceof ArrayCopySlowPathNode) {
 319             arraycopySnippets.lower((ArrayCopySlowPathNode) n, tool);
 320         } else if (n instanceof ArrayCopyUnrollNode) {
 321             arraycopySnippets.lower((ArrayCopyUnrollNode) n, tool);
 322         } else if (n instanceof G1PreWriteBarrier) {
 323             writeBarrierSnippets.lower((G1PreWriteBarrier) n, registers, tool);
 324         } else if (n instanceof G1PostWriteBarrier) {
 325             writeBarrierSnippets.lower((G1PostWriteBarrier) n, registers, tool);
 326         } else if (n instanceof G1ReferentFieldReadBarrier) {
 327             writeBarrierSnippets.lower((G1ReferentFieldReadBarrier) n, registers, tool);
 328         } else if (n instanceof SerialWriteBarrier) {
 329             writeBarrierSnippets.lower((SerialWriteBarrier) n, tool);
 330         } else if (n instanceof SerialArrayRangeWriteBarrier) {
 331             writeBarrierSnippets.lower((SerialArrayRangeWriteBarrier) n, tool);
 332         } else if (n instanceof G1ArrayRangePreWriteBarrier) {
 333             writeBarrierSnippets.lower((G1ArrayRangePreWriteBarrier) n, registers, tool);
 334         } else if (n instanceof G1ArrayRangePostWriteBarrier) {
 335             writeBarrierSnippets.lower((G1ArrayRangePostWriteBarrier) n, registers, tool);
 336         } else if (n instanceof NewMultiArrayNode) {
 337             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 338                 newObjectSnippets.lower((NewMultiArrayNode) n, tool);
 339             }
 340         } else if (n instanceof LoadExceptionObjectNode) {
 341             exceptionObjectSnippets.lower((LoadExceptionObjectNode) n, registers, tool);
 342         } else if (n instanceof AssertionNode) {
 343             assertionSnippets.lower((AssertionNode) n, tool);
 344         } else if (n instanceof StringToBytesNode) {
 345             if (graph.getGuardsStage().areDeoptsFixed()) {
 346                 stringToBytesSnippets.lower((StringToBytesNode) n, tool);
 347             }
 348         } else if (n instanceof IntegerDivRemNode) {
 349             // Nothing to do for division nodes. The HotSpot signal handler catches divisions by
 350             // zero and the MIN_VALUE / -1 cases.
 351         } else if (n instanceof AbstractDeoptimizeNode || n instanceof UnwindNode || n instanceof RemNode || n instanceof SafepointNode) {
 352             /* No lowering, we generate LIR directly for these nodes. */
 353         } else if (n instanceof ClassGetHubNode) {
 354             lowerClassGetHubNode((ClassGetHubNode) n, tool);
 355         } else if (n instanceof HubGetClassNode) {
 356             lowerHubGetClassNode((HubGetClassNode) n, tool);
 357         } else if (n instanceof KlassLayoutHelperNode) {
 358             lowerKlassLayoutHelperNode((KlassLayoutHelperNode) n, tool);
 359         } else if (n instanceof ComputeObjectAddressNode) {
 360             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 361                 lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
 362             }
 363         } else if (n instanceof IdentityHashCodeNode) {
 364             hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
 365         } else if (n instanceof ResolveDynamicConstantNode) {
 366             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 367                 resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
 368             }
 369         } else if (n instanceof ResolveConstantNode) {
 370             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 371                 resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
 372             }
 373         } else if (n instanceof ResolveMethodAndLoadCountersNode) {
 374             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 375                 resolveConstantSnippets.lower((ResolveMethodAndLoadCountersNode) n, tool);
 376             }
 377         } else if (n instanceof InitializeKlassNode) {
 378             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 379                 resolveConstantSnippets.lower((InitializeKlassNode) n, tool);
 380             }
 381         } else if (n instanceof ProfileNode) {
 382             profileSnippets.lower((ProfileNode) n, tool);
 383         } else {
 384             super.lower(n, tool);
 385         }
 386     }
 387 
 388     private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
 389         /*
 390          * Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
 391          * potential safepoints and above it's uses.
 392          */
 393         for (Node use : n.usages().snapshot()) {
 394             if (use instanceof FixedNode) {
 395                 FixedNode fixed = (FixedNode) use;
 396                 StructuredGraph graph = n.graph();
 397                 GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
 398                 graph.addBeforeFixed(fixed, address);
 399                 AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
 400                 use.replaceFirstInput(n, add);
 401             } else {
 402                 throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
 403             }
 404         }
 405         GraphUtil.unlinkFixedNode(n);
 406         n.safeDelete();
 407     }
 408 
 409     private void lowerKlassLayoutHelperNode(KlassLayoutHelperNode n, LoweringTool tool) {
 410         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 411             return;
 412         }
 413         StructuredGraph graph = n.graph();
 414         assert !n.getHub().isConstant();
 415         AddressNode address = createOffsetAddress(graph, n.getHub(), runtime.getVMConfig().klassLayoutHelperOffset);
 416         n.replaceAtUsagesAndDelete(graph.unique(new FloatingReadNode(address, KLASS_LAYOUT_HELPER_LOCATION, null, n.stamp(), null, BarrierType.NONE)));
 417     }
 418 
 419     private void lowerHubGetClassNode(HubGetClassNode n, LoweringTool tool) {
 420         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 421             return;
 422         }
 423 
 424         ValueNode hub = n.getHub();
 425         GraalHotSpotVMConfig vmConfig = runtime.getVMConfig();
 426         StructuredGraph graph = n.graph();
 427         assert !hub.isConstant() || GraalOptions.ImmutableCode.getValue(graph.getOptions());
 428         AddressNode mirrorAddress = createOffsetAddress(graph, hub, vmConfig.classMirrorOffset);
 429         FloatingReadNode read = graph.unique(new FloatingReadNode(mirrorAddress, CLASS_MIRROR_LOCATION, null, vmConfig.classMirrorIsHandle ? StampFactory.forKind(target.wordJavaKind) : n.stamp(),
 430                         null, BarrierType.NONE));
 431         if (vmConfig.classMirrorIsHandle) {
 432             AddressNode address = createOffsetAddress(graph, read, 0);
 433             read = graph.unique(new FloatingReadNode(address, CLASS_MIRROR_HANDLE_LOCATION, null, n.stamp(), null, BarrierType.NONE));
 434         }
 435         n.replaceAtUsagesAndDelete(read);
 436     }
 437 
 438     private void lowerClassGetHubNode(ClassGetHubNode n, LoweringTool tool) {
 439         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 440             return;
 441         }
 442 
 443         StructuredGraph graph = n.graph();
 444         assert !n.getValue().isConstant();
 445         AddressNode address = createOffsetAddress(graph, n.getValue(), runtime.getVMConfig().klassOffset);
 446         FloatingReadNode read = graph.unique(new FloatingReadNode(address, CLASS_KLASS_LOCATION, null, n.stamp(), null, BarrierType.NONE));
 447         n.replaceAtUsagesAndDelete(read);
 448     }
 449 
 450     private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
 451         if (invoke.callTarget() instanceof MethodCallTargetNode) {
 452             MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
 453             NodeInputList<ValueNode> parameters = callTarget.arguments();
 454             ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
 455             if (!callTarget.isStatic() && receiver.stamp() instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
 456                 ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
 457                 parameters.set(0, nonNullReceiver);
 458                 receiver = nonNullReceiver;
 459             }
 460             JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
 461 
 462             LoweredCallTargetNode loweredCallTarget = null;
 463             OptionValues options = graph.getOptions();
 464             if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
 465                 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
 466                 ResolvedJavaType receiverType = invoke.getReceiverType();
 467                 if (hsMethod.isInVirtualMethodTable(receiverType)) {
 468                     JavaKind wordKind = runtime.getTarget().wordJavaKind;
 469                     ValueNode hub = createReadHub(graph, receiver, tool);
 470 
 471                     ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
 472                     // We use LocationNode.ANY_LOCATION for the reads that access the
 473                     // compiled code entry as HotSpot does not guarantee they are final
 474                     // values.
 475                     int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
 476                     AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
 477                     ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
 478 
 479                     loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 480                                     signature, callTarget.targetMethod(),
 481                                     HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
 482 
 483                     graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
 484                     graph.addAfterFixed(metaspaceMethod, compiledEntry);
 485                 }
 486             }
 487 
 488             if (loweredCallTarget == null) {
 489                 loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 490                                 signature, callTarget.targetMethod(),
 491                                 HotSpotCallingConventionType.JavaCall,
 492                                 callTarget.invokeKind()));
 493             }
 494             callTarget.replaceAndDelete(loweredCallTarget);
 495         }
 496     }
 497 
 498     @Override
 499     protected Stamp loadStamp(Stamp stamp, JavaKind kind, boolean compressible) {
 500         if (kind == JavaKind.Object && compressible && runtime.getVMConfig().useCompressedOops) {
 501             return HotSpotNarrowOopStamp.compressed((ObjectStamp) stamp, runtime.getVMConfig().getOopEncoding());
 502         }
 503         return super.loadStamp(stamp, kind, compressible);
 504     }
 505 
 506     @Override
 507     protected ValueNode implicitLoadConvert(JavaKind kind, ValueNode value, boolean compressible) {
 508         if (kind == JavaKind.Object && compressible && runtime.getVMConfig().useCompressedOops) {
 509             return new HotSpotCompressionNode(CompressionOp.Uncompress, value, runtime.getVMConfig().getOopEncoding());
 510         }
 511         return super.implicitLoadConvert(kind, value, compressible);



 512     }
 513 
 514     @Override
 515     public ValueNode staticFieldBase(StructuredGraph graph, ResolvedJavaField f) {
 516         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 517         JavaConstant base = constantReflection.asJavaClass(field.getDeclaringClass());
 518         return ConstantNode.forConstant(base, metaAccess, graph);
 519     }
 520 
 521     @Override
 522     protected ValueNode implicitStoreConvert(JavaKind kind, ValueNode value, boolean compressible) {
 523         if (kind == JavaKind.Object && compressible && runtime.getVMConfig().useCompressedOops) {
 524             return new HotSpotCompressionNode(CompressionOp.Compress, value, runtime.getVMConfig().getOopEncoding());
 525         }
 526         return super.implicitStoreConvert(kind, value, compressible);
 527     }
 528 
 529     @Override
 530     protected ValueNode createReadArrayComponentHub(StructuredGraph graph, ValueNode arrayHub, FixedNode anchor) {
 531         /*
 532          * Anchor the read of the element klass to the cfg, because it is only valid when arrayClass
 533          * is an object class, which might not be the case in other parts of the compiled method.
 534          */
 535         AddressNode address = createOffsetAddress(graph, arrayHub, runtime.getVMConfig().arrayClassElementOffset);
 536         return graph.unique(new FloatingReadNode(address, OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION, null, KlassPointerStamp.klassNonNull(), AbstractBeginNode.prevBegin(anchor)));
 537     }
 538 
 539     @Override
 540     protected void lowerUnsafeLoadNode(RawLoadNode load, LoweringTool tool) {
 541         StructuredGraph graph = load.graph();
 542         if (!(load instanceof GuardedUnsafeLoadNode) && !graph.getGuardsStage().allowsFloatingGuards() && addReadBarrier(load)) {
 543             unsafeLoadSnippets.lower(load, tool);
 544         } else {
 545             super.lowerUnsafeLoadNode(load, tool);
 546         }
 547     }
 548 
 549     private void lowerLoadMethodNode(LoadMethodNode loadMethodNode) {
 550         StructuredGraph graph = loadMethodNode.graph();
 551         HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) loadMethodNode.getMethod();
 552         ReadNode metaspaceMethod = createReadVirtualMethod(graph, loadMethodNode.getHub(), method, loadMethodNode.getReceiverType());
 553         graph.replaceFixed(loadMethodNode, metaspaceMethod);
 554     }
 555 
 556     private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
 557         StampProvider stampProvider = tool.getStampProvider();
 558         LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
 559         HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
 560         getClass.replaceAtUsagesAndDelete(hubGetClass);
 561         hub.lower(tool);
 562         hubGetClass.lower(tool);
 563     }
 564 
 565     private void lowerStoreHubNode(StoreHubNode storeHub, StructuredGraph graph) {
 566         WriteNode hub = createWriteHub(graph, storeHub.getObject(), storeHub.getValue());
 567         graph.replaceFixed(storeHub, hub);
 568     }
 569 
 570     @Override
 571     public BarrierType fieldInitializationBarrier(JavaKind entryKind) {
 572         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.IMPRECISE : BarrierType.NONE;
 573     }
 574 
 575     @Override
 576     public BarrierType arrayInitializationBarrier(JavaKind entryKind) {
 577         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.PRECISE : BarrierType.NONE;
 578     }
 579 
 580     private void lowerOSRStartNode(OSRStartNode osrStart) {
 581         StructuredGraph graph = osrStart.graph();
 582         if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
 583             StartNode newStart = graph.add(new StartNode());
 584             ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
 585             ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
 586             migrationEnd.setStateAfter(osrStart.stateAfter());
 587             newStart.setNext(migrationEnd);
 588             FixedNode next = osrStart.next();
 589             osrStart.setNext(null);
 590             migrationEnd.setNext(next);
 591             graph.setStart(newStart);
 592 
 593             final int wordSize = target.wordSize;
 594 
 595             // @formatter:off
 596             // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
 597             // @formatter:on
 598             int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
 599             for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
 600                 int size = osrLocal.getStackKind().getSlotCount();
 601                 int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
 602                 AddressNode address = createOffsetAddress(graph, buffer, offset);
 603                 ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(), BarrierType.NONE));
 604                 osrLocal.replaceAndDelete(load);
 605                 graph.addBeforeFixed(migrationEnd, load);
 606             }
 607 
 608             // @formatter:off
 609             // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
 610             // @formatter:on
 611             final int lockCount = osrStart.stateAfter().locksSize();
 612             final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
 613 
 614             // first initialize the lock slots for all enters with the displaced marks read from the
 615             // buffer
 616             for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
 617                 MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
 618                 OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
 619                 final int index = lock.index();
 620 
 621                 final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
 622                 final int offsetLockObject = locksOffset - index * 2 * wordSize;
 623 
 624                 // load the displaced mark from the osr buffer
 625                 AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
 626                 ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(), BarrierType.NONE));
 627                 graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
 628 
 629                 // we need to initialize the stack slot for the lock
 630                 BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
 631                 graph.addBeforeFixed(migrationEnd, beginLockScope);
 632 
 633                 // write the displaced mark to the correct stack slot
 634                 AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
 635                 WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
 636                 graph.addBeforeFixed(migrationEnd, writeStackSlot);
 637 
 638                 // load the lock object from the osr buffer
 639                 AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
 640                 ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(), BarrierType.NONE));
 641                 lock.replaceAndDelete(loadObject);
 642                 graph.addBeforeFixed(migrationEnd, loadObject);
 643             }
 644 
 645             osrStart.replaceAtUsagesAndDelete(newStart);
 646         }
 647     }
 648 
 649     static final class Exceptions {
 650         protected static final ArrayIndexOutOfBoundsException cachedArrayIndexOutOfBoundsException;
 651         protected static final NullPointerException cachedNullPointerException;
 652 
 653         static {
 654             cachedArrayIndexOutOfBoundsException = new ArrayIndexOutOfBoundsException();
 655             cachedArrayIndexOutOfBoundsException.setStackTrace(new StackTraceElement[0]);
 656             cachedNullPointerException = new NullPointerException();
 657             cachedNullPointerException.setStackTrace(new StackTraceElement[0]);
 658         }
 659     }
 660 
 661     public static final class RuntimeCalls {
 662         public static final ForeignCallDescriptor CREATE_ARRAY_STORE_EXCEPTION = new ForeignCallDescriptor("createArrayStoreException", ArrayStoreException.class, Object.class);
 663         public static final ForeignCallDescriptor CREATE_CLASS_CAST_EXCEPTION = new ForeignCallDescriptor("createClassCastException", ClassCastException.class, Object.class, KlassPointer.class);
 664         public static final ForeignCallDescriptor CREATE_NULL_POINTER_EXCEPTION = new ForeignCallDescriptor("createNullPointerException", NullPointerException.class);
 665         public static final ForeignCallDescriptor CREATE_OUT_OF_BOUNDS_EXCEPTION = new ForeignCallDescriptor("createOutOfBoundsException", ArrayIndexOutOfBoundsException.class, int.class);
 666     }
 667 
 668     private boolean throwCachedException(BytecodeExceptionNode node) {
 669         Throwable exception;
 670         if (node.getExceptionClass() == NullPointerException.class) {
 671             exception = Exceptions.cachedNullPointerException;
 672         } else if (node.getExceptionClass() == ArrayIndexOutOfBoundsException.class) {
 673             exception = Exceptions.cachedArrayIndexOutOfBoundsException;
 674         } else {
 675             return false;
 676         }
 677 
 678         StructuredGraph graph = node.graph();
 679         FloatingNode exceptionNode = ConstantNode.forConstant(constantReflection.forObject(exception), metaAccess, graph);
 680         graph.replaceFixedWithFloating(node, exceptionNode);
 681         return true;
 682     }
 683 
 684     private void lowerBytecodeExceptionNode(BytecodeExceptionNode node) {
 685         if (OmitHotExceptionStacktrace.getValue(node.getOptions())) {
 686             if (throwCachedException(node)) {
 687                 return;
 688             }
 689         }
 690 
 691         ForeignCallDescriptor descriptor;
 692         if (node.getExceptionClass() == NullPointerException.class) {
 693             descriptor = RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION;
 694         } else if (node.getExceptionClass() == ArrayIndexOutOfBoundsException.class) {
 695             descriptor = RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION;
 696         } else if (node.getExceptionClass() == ArrayStoreException.class) {
 697             descriptor = RuntimeCalls.CREATE_ARRAY_STORE_EXCEPTION;
 698         } else if (node.getExceptionClass() == ClassCastException.class) {
 699             descriptor = RuntimeCalls.CREATE_CLASS_CAST_EXCEPTION;
 700         } else {
 701             throw GraalError.shouldNotReachHere();
 702         }
 703 
 704         StructuredGraph graph = node.graph();
 705         ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(foreignCalls, descriptor, node.stamp(), node.getArguments()));
 706         graph.replaceFixedWithFixed(node, foreignCallNode);
 707     }
 708 
 709     private boolean addReadBarrier(RawLoadNode load) {
 710         if (runtime.getVMConfig().useG1GC && load.graph().getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS && load.object().getStackKind() == JavaKind.Object &&
 711                         load.accessKind() == JavaKind.Object && !StampTool.isPointerAlwaysNull(load.object())) {
 712             ResolvedJavaType type = StampTool.typeOrNull(load.object());
 713             if (type != null && !type.isArray()) {
 714                 return true;
 715             }
 716         }
 717         return false;
 718     }
 719 
 720     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, HotSpotResolvedJavaMethod method, ResolvedJavaType receiverType) {
 721         return createReadVirtualMethod(graph, hub, method.vtableEntryOffset(receiverType));
 722     }
 723 
 724     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, int vtableEntryOffset) {
 725         assert vtableEntryOffset > 0;
 726         // We use LocationNode.ANY_LOCATION for the reads that access the vtable
 727         // entry as HotSpot does not guarantee that this is a final value.
 728         Stamp methodStamp = MethodPointerStamp.methodNonNull();
 729         AddressNode address = createOffsetAddress(graph, hub, vtableEntryOffset);
 730         ReadNode metaspaceMethod = graph.add(new ReadNode(address, any(), methodStamp, BarrierType.NONE));
 731         return metaspaceMethod;
 732     }
 733 
 734     @Override
 735     protected ValueNode createReadHub(StructuredGraph graph, ValueNode object, LoweringTool tool) {
 736         if (tool.getLoweringStage() != LoweringTool.StandardLoweringStage.LOW_TIER) {
 737             return graph.unique(new LoadHubNode(tool.getStampProvider(), object));
 738         }
 739         assert !object.isConstant() || object.isNullConstant();
 740 
 741         KlassPointerStamp hubStamp = KlassPointerStamp.klassNonNull();
 742         if (runtime.getVMConfig().useCompressedClassPointers) {
 743             hubStamp = hubStamp.compressed(runtime.getVMConfig().getKlassEncoding());
 744         }
 745 
 746         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 747         LocationIdentity hubLocation = runtime.getVMConfig().useCompressedClassPointers ? COMPRESSED_HUB_LOCATION : HUB_LOCATION;
 748         FloatingReadNode memoryRead = graph.unique(new FloatingReadNode(address, hubLocation, null, hubStamp, null, BarrierType.NONE));
 749         if (runtime.getVMConfig().useCompressedClassPointers) {
 750             return HotSpotCompressionNode.uncompress(memoryRead, runtime.getVMConfig().getKlassEncoding());
 751         } else {
 752             return memoryRead;
 753         }
 754     }
 755 
 756     private WriteNode createWriteHub(StructuredGraph graph, ValueNode object, ValueNode value) {
 757         assert !object.isConstant() || object.asConstant().isDefaultForKind();
 758 
 759         ValueNode writeValue = value;
 760         if (runtime.getVMConfig().useCompressedClassPointers) {
 761             writeValue = HotSpotCompressionNode.compress(value, runtime.getVMConfig().getKlassEncoding());
 762         }
 763 
 764         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 765         return graph.add(new WriteNode(address, HUB_WRITE_LOCATION, writeValue, BarrierType.NONE));
 766     }
 767 
 768     @Override
 769     protected BarrierType fieldLoadBarrierType(ResolvedJavaField f) {
 770         HotSpotResolvedJavaField loadField = (HotSpotResolvedJavaField) f;
 771         BarrierType barrierType = BarrierType.NONE;
 772         if (runtime.getVMConfig().useG1GC && loadField.getJavaKind() == JavaKind.Object && metaAccess.lookupJavaType(Reference.class).equals(loadField.getDeclaringClass()) &&
 773                         loadField.getName().equals("referent")) {
 774             barrierType = BarrierType.PRECISE;
 775         }
 776         return barrierType;
 777     }
 778 
 779     @Override
 780     public int fieldOffset(ResolvedJavaField f) {
 781         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 782         return field.offset();
 783     }
 784 
 785     @Override
 786     public int arrayScalingFactor(JavaKind kind) {
 787         if (runtime.getVMConfig().useCompressedOops && kind == JavaKind.Object) {
 788             return super.arrayScalingFactor(JavaKind.Int);
 789         } else {
 790             return super.arrayScalingFactor(kind);
 791         }
 792     }
 793 
 794     @Override
 795     public int arrayBaseOffset(JavaKind kind) {
 796         return getArrayBaseOffset(kind);
 797     }
 798 
 799     @Override
 800     public int arrayLengthOffset() {
 801         return runtime.getVMConfig().arrayOopDescLengthOffset();





 802     }
 803 }
--- EOF ---