1 /*
   2  * Copyright (c) 2011, 2018, 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 
  24 
  25 package org.graalvm.compiler.hotspot.meta;
  26 

  27 import static org.graalvm.compiler.core.common.GraalOptions.AlwaysInlineVTableStubs;
  28 import static org.graalvm.compiler.core.common.GraalOptions.InlineVTableStubs;
  29 import static org.graalvm.compiler.core.common.GraalOptions.OmitHotExceptionStacktrace;
  30 import static org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProviderImpl.OSR_MIGRATION_END;
  31 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_KLASS_LOCATION;
  32 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_HANDLE_LOCATION;
  33 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_LOCATION;
  34 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.COMPRESSED_HUB_LOCATION;
  35 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.DISPLACED_MARK_WORD_LOCATION;
  36 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_LOCATION;
  37 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.HUB_WRITE_LOCATION;
  38 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.KLASS_LAYOUT_HELPER_LOCATION;
  39 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION;
  40 import static jdk.internal.vm.compiler.word.LocationIdentity.any;
  41 
  42 import java.lang.ref.Reference;
  43 import java.util.EnumMap;
  44 
  45 import org.graalvm.compiler.api.directives.GraalDirectives;
  46 import org.graalvm.compiler.core.common.CompressEncoding;
  47 import org.graalvm.compiler.core.common.GraalOptions;
  48 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  49 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  50 import org.graalvm.compiler.core.common.type.ObjectStamp;
  51 import org.graalvm.compiler.core.common.type.Stamp;
  52 import org.graalvm.compiler.core.common.type.StampFactory;
  53 import org.graalvm.compiler.core.common.type.StampPair;
  54 import org.graalvm.compiler.debug.DebugCloseable;
  55 import org.graalvm.compiler.debug.DebugHandlersFactory;
  56 import org.graalvm.compiler.debug.GraalError;
  57 import org.graalvm.compiler.graph.Node;
  58 import org.graalvm.compiler.graph.NodeInputList;
  59 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  60 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;







  61 import org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode;
  62 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier;
  63 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier;
  64 import org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier;
  65 import org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier;
  66 import org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier;
  67 import org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode;
  68 import org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode;
  69 import org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode;
  70 import org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier;
  71 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
  72 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
  73 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
  74 import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
  75 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
  76 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  77 import org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp;
  78 import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp;
  79 import org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp;
  80 import org.graalvm.compiler.hotspot.replacements.AssertionSnippets;
  81 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  82 import org.graalvm.compiler.hotspot.replacements.HashCodeSnippets;
  83 import org.graalvm.compiler.hotspot.replacements.HubGetClassNode;
  84 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  85 import org.graalvm.compiler.hotspot.replacements.InstanceOfSnippets;
  86 import org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode;
  87 import org.graalvm.compiler.hotspot.replacements.LoadExceptionObjectSnippets;
  88 import org.graalvm.compiler.hotspot.replacements.MonitorSnippets;
  89 import org.graalvm.compiler.hotspot.replacements.NewObjectSnippets;
  90 import org.graalvm.compiler.hotspot.replacements.ObjectCloneSnippets;
  91 import org.graalvm.compiler.hotspot.replacements.StringToBytesSnippets;
  92 import org.graalvm.compiler.hotspot.replacements.UnsafeLoadSnippets;
  93 import org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets;
  94 import org.graalvm.compiler.hotspot.replacements.aot.ResolveConstantSnippets;
  95 import org.graalvm.compiler.hotspot.replacements.arraycopy.HotSpotArraycopySnippets;
  96 import org.graalvm.compiler.hotspot.replacements.profiling.ProfileSnippets;
  97 import org.graalvm.compiler.hotspot.stubs.ForeignCallSnippets;
  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.ComputeObjectAddressNode;
 103 import org.graalvm.compiler.nodes.ConstantNode;
 104 import org.graalvm.compiler.nodes.FixedNode;
 105 import org.graalvm.compiler.nodes.GetObjectAddressNode;
 106 import org.graalvm.compiler.nodes.Invoke;
 107 import org.graalvm.compiler.nodes.LogicNode;
 108 import org.graalvm.compiler.nodes.LoweredCallTargetNode;
 109 import org.graalvm.compiler.nodes.NodeView;
 110 import org.graalvm.compiler.nodes.ParameterNode;
 111 import org.graalvm.compiler.nodes.SafepointNode;
 112 import org.graalvm.compiler.nodes.StartNode;
 113 import org.graalvm.compiler.nodes.StructuredGraph;
 114 import org.graalvm.compiler.nodes.UnwindNode;
 115 import org.graalvm.compiler.nodes.ValueNode;
 116 import org.graalvm.compiler.nodes.calc.AddNode;
 117 import org.graalvm.compiler.nodes.calc.FloatingNode;
 118 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
 119 import org.graalvm.compiler.nodes.calc.IsNullNode;
 120 import org.graalvm.compiler.nodes.calc.RemNode;
 121 import org.graalvm.compiler.nodes.debug.StringToBytesNode;
 122 import org.graalvm.compiler.nodes.debug.VerifyHeapNode;
 123 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 124 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode.BytecodeExceptionKind;
 125 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
 126 import org.graalvm.compiler.nodes.extended.GetClassNode;
 127 import org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode;
 128 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 129 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 130 import org.graalvm.compiler.nodes.extended.OSRLocalNode;
 131 import org.graalvm.compiler.nodes.extended.OSRLockNode;
 132 import org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode;
 133 import org.graalvm.compiler.nodes.extended.OSRStartNode;
 134 import org.graalvm.compiler.nodes.extended.RawLoadNode;
 135 import org.graalvm.compiler.nodes.extended.StoreHubNode;
 136 import org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode;
 137 import org.graalvm.compiler.nodes.java.DynamicNewArrayNode;
 138 import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode;
 139 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
 140 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 141 import org.graalvm.compiler.nodes.java.LoadExceptionObjectNode;
 142 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 143 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 144 import org.graalvm.compiler.nodes.java.MonitorIdNode;
 145 import org.graalvm.compiler.nodes.java.NewArrayNode;
 146 import org.graalvm.compiler.nodes.java.NewInstanceNode;
 147 import org.graalvm.compiler.nodes.java.NewMultiArrayNode;
 148 import org.graalvm.compiler.nodes.java.RawMonitorEnterNode;
 149 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
 150 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
 151 import org.graalvm.compiler.nodes.memory.ReadNode;
 152 import org.graalvm.compiler.nodes.memory.WriteNode;
 153 import org.graalvm.compiler.nodes.memory.address.AddressNode;
 154 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 155 import org.graalvm.compiler.nodes.spi.LoweringTool;
 156 import org.graalvm.compiler.nodes.spi.StampProvider;
 157 import org.graalvm.compiler.nodes.type.StampTool;
 158 import org.graalvm.compiler.nodes.util.GraphUtil;
 159 import org.graalvm.compiler.options.OptionValues;
 160 import org.graalvm.compiler.replacements.DefaultJavaLoweringProvider;
 161 import org.graalvm.compiler.replacements.arraycopy.ArrayCopyNode;
 162 import org.graalvm.compiler.replacements.arraycopy.ArrayCopySnippets;
 163 import org.graalvm.compiler.replacements.arraycopy.ArrayCopyWithSlowPathNode;
 164 import org.graalvm.compiler.replacements.nodes.AssertionNode;

 165 import jdk.internal.vm.compiler.word.LocationIdentity;
 166 
 167 import jdk.vm.ci.code.TargetDescription;
 168 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
 169 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
 170 import jdk.vm.ci.hotspot.HotSpotResolvedJavaField;
 171 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 172 import jdk.vm.ci.meta.JavaConstant;
 173 import jdk.vm.ci.meta.JavaKind;
 174 import jdk.vm.ci.meta.JavaType;
 175 import jdk.vm.ci.meta.MetaAccessProvider;
 176 import jdk.vm.ci.meta.ResolvedJavaField;
 177 import jdk.vm.ci.meta.ResolvedJavaType;
 178 
 179 /**
 180  * HotSpot implementation of {@link LoweringProvider}.
 181  */
 182 public class DefaultHotSpotLoweringProvider extends DefaultJavaLoweringProvider implements HotSpotLoweringProvider {
 183 
 184     protected final HotSpotGraalRuntimeProvider runtime;
 185     protected final HotSpotRegistersProvider registers;
 186     protected final HotSpotConstantReflectionProvider constantReflection;
 187 
 188     protected InstanceOfSnippets.Templates instanceofSnippets;
 189     protected NewObjectSnippets.Templates newObjectSnippets;
 190     protected MonitorSnippets.Templates monitorSnippets;
 191     protected WriteBarrierSnippets.Templates writeBarrierSnippets;
 192     protected LoadExceptionObjectSnippets.Templates exceptionObjectSnippets;
 193     protected UnsafeLoadSnippets.Templates unsafeLoadSnippets;
 194     protected AssertionSnippets.Templates assertionSnippets;
 195     protected ArrayCopySnippets.Templates arraycopySnippets;
 196     protected StringToBytesSnippets.Templates stringToBytesSnippets;
 197     protected HashCodeSnippets.Templates hashCodeSnippets;
 198     protected ResolveConstantSnippets.Templates resolveConstantSnippets;
 199     protected ProfileSnippets.Templates profileSnippets;
 200 
 201     protected ObjectCloneSnippets.Templates objectCloneSnippets;
 202     protected ForeignCallSnippets.Templates foreignCallSnippets;
 203 
 204     public DefaultHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
 205                     HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
 206         super(metaAccess, foreignCalls, target, runtime.getVMConfig().useCompressedOops);
 207         this.runtime = runtime;
 208         this.registers = registers;
 209         this.constantReflection = constantReflection;
 210     }
 211 
 212     @Override
 213     public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
 214         super.initialize(options, factories, runtime, providers, providers.getSnippetReflection());
 215 
 216         assert target == providers.getCodeCache().getTarget();
 217         instanceofSnippets = new InstanceOfSnippets.Templates(options, factories, runtime, providers, target);
 218         newObjectSnippets = new NewObjectSnippets.Templates(options, factories, runtime, providers, target, config);
 219         monitorSnippets = new MonitorSnippets.Templates(options, factories, runtime, providers, target, config.useFastLocking);
 220         writeBarrierSnippets = new WriteBarrierSnippets.Templates(options, factories, runtime, providers, target, config);
 221         exceptionObjectSnippets = new LoadExceptionObjectSnippets.Templates(options, factories, providers, target);
 222         unsafeLoadSnippets = new UnsafeLoadSnippets.Templates(options, factories, providers, target);
 223         assertionSnippets = new AssertionSnippets.Templates(options, factories, providers, target);
 224         arraycopySnippets = new ArrayCopySnippets.Templates(new HotSpotArraycopySnippets(), options, factories, runtime, providers, providers.getSnippetReflection(), target);
 225         stringToBytesSnippets = new StringToBytesSnippets.Templates(options, factories, providers, target);
 226         hashCodeSnippets = new HashCodeSnippets.Templates(options, factories, providers, target);
 227         resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
 228         profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);


 229         objectCloneSnippets = new ObjectCloneSnippets.Templates(options, factories, providers, target);
 230         foreignCallSnippets = new ForeignCallSnippets.Templates(options, factories, providers, target);
 231     }
 232 
 233     public MonitorSnippets.Templates getMonitorSnippets() {
 234         return monitorSnippets;
 235     }
 236 
 237     @Override
 238     @SuppressWarnings("try")
 239     public void lower(Node n, LoweringTool tool) {
 240         StructuredGraph graph = (StructuredGraph) n.graph();
 241         try (DebugCloseable context = n.withNodeSourcePosition()) {
 242             if (n instanceof Invoke) {
 243                 lowerInvoke((Invoke) n, tool, graph);
 244             } else if (n instanceof LoadMethodNode) {
 245                 lowerLoadMethodNode((LoadMethodNode) n);
 246             } else if (n instanceof GetClassNode) {
 247                 lowerGetClassNode((GetClassNode) n, tool, graph);
 248             } else if (n instanceof StoreHubNode) {
 249                 lowerStoreHubNode((StoreHubNode) n, graph);
 250             } else if (n instanceof OSRStartNode) {
 251                 lowerOSRStartNode((OSRStartNode) n);
 252             } else if (n instanceof BytecodeExceptionNode) {
 253                 lowerBytecodeExceptionNode((BytecodeExceptionNode) n);
 254             } else if (n instanceof InstanceOfNode) {
 255                 InstanceOfNode instanceOfNode = (InstanceOfNode) n;
 256                 if (graph.getGuardsStage().areDeoptsFixed()) {
 257                     instanceofSnippets.lower(instanceOfNode, tool);
 258                 } else {
 259                     if (instanceOfNode.allowsNull()) {
 260                         ValueNode object = instanceOfNode.getValue();
 261                         LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfNode.create(instanceOfNode.type(), object, instanceOfNode.profile(), instanceOfNode.getAnchor()));
 262                         LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 263                         instanceOfNode.replaceAndDelete(newNode);
 264                     }
 265                 }
 266             } else if (n instanceof InstanceOfDynamicNode) {
 267                 InstanceOfDynamicNode instanceOfDynamicNode = (InstanceOfDynamicNode) n;
 268                 if (graph.getGuardsStage().areDeoptsFixed()) {
 269                     instanceofSnippets.lower(instanceOfDynamicNode, tool);
 270                 } else {
 271                     ValueNode mirror = instanceOfDynamicNode.getMirrorOrHub();
 272                     if (mirror.stamp(NodeView.DEFAULT).getStackKind() == JavaKind.Object) {
 273                         ClassGetHubNode classGetHub = graph.unique(new ClassGetHubNode(mirror));
 274                         instanceOfDynamicNode.setMirror(classGetHub);
 275                     }
 276 
 277                     if (instanceOfDynamicNode.allowsNull()) {
 278                         ValueNode object = instanceOfDynamicNode.getObject();
 279                         LogicNode newTypeCheck = graph.addOrUniqueWithInputs(
 280                                         InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), instanceOfDynamicNode.getMirrorOrHub(), object, false));
 281                         LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 282                         instanceOfDynamicNode.replaceAndDelete(newNode);
 283                     }
 284                 }
 285             } else if (n instanceof ClassIsAssignableFromNode) {
 286                 if (graph.getGuardsStage().areDeoptsFixed()) {
 287                     instanceofSnippets.lower((ClassIsAssignableFromNode) n, tool);
 288                 }
 289             } else if (n instanceof NewInstanceNode) {
 290                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 291                     newObjectSnippets.lower((NewInstanceNode) n, registers, tool);
 292                 }
 293             } else if (n instanceof DynamicNewInstanceNode) {
 294                 DynamicNewInstanceNode newInstanceNode = (DynamicNewInstanceNode) n;
 295                 if (newInstanceNode.getClassClass() == null) {
 296                     JavaConstant classClassMirror = constantReflection.asJavaClass(metaAccess.lookupJavaType(Class.class));
 297                     ConstantNode classClass = ConstantNode.forConstant(classClassMirror, tool.getMetaAccess(), graph);
 298                     newInstanceNode.setClassClass(classClass);
 299                 }
 300                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 301                     newObjectSnippets.lower(newInstanceNode, registers, tool);
 302                 }
 303             } else if (n instanceof NewArrayNode) {
 304                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 305                     newObjectSnippets.lower((NewArrayNode) n, registers, tool);
 306                 }
 307             } else if (n instanceof DynamicNewArrayNode) {
 308                 DynamicNewArrayNode dynamicNewArrayNode = (DynamicNewArrayNode) n;
 309                 if (dynamicNewArrayNode.getVoidClass() == null) {
 310                     JavaConstant voidClassMirror = constantReflection.asJavaClass(metaAccess.lookupJavaType(void.class));
 311                     ConstantNode voidClass = ConstantNode.forConstant(voidClassMirror, tool.getMetaAccess(), graph);
 312                     dynamicNewArrayNode.setVoidClass(voidClass);
 313                 }
 314                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 315                     newObjectSnippets.lower(dynamicNewArrayNode, registers, tool);
 316                 }
 317             } else if (n instanceof VerifyHeapNode) {
 318                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 319                     newObjectSnippets.lower((VerifyHeapNode) n, registers, tool);
 320                 }
 321             } else if (n instanceof RawMonitorEnterNode) {
 322                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 323                     monitorSnippets.lower((RawMonitorEnterNode) n, registers, tool);
 324                 }
 325             } else if (n instanceof MonitorExitNode) {
 326                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 327                     monitorSnippets.lower((MonitorExitNode) n, registers, tool);
 328                 }
 329             } else if (n instanceof ArrayCopyNode) {
 330                 arraycopySnippets.lower((ArrayCopyNode) n, tool);
 331             } else if (n instanceof ArrayCopyWithSlowPathNode) {
 332                 arraycopySnippets.lower((ArrayCopyWithSlowPathNode) n, tool);
 333             } else if (n instanceof G1PreWriteBarrier) {
 334                 writeBarrierSnippets.lower((G1PreWriteBarrier) n, registers, tool);
 335             } else if (n instanceof G1PostWriteBarrier) {
 336                 writeBarrierSnippets.lower((G1PostWriteBarrier) n, registers, tool);
 337             } else if (n instanceof G1ReferentFieldReadBarrier) {
 338                 writeBarrierSnippets.lower((G1ReferentFieldReadBarrier) n, registers, tool);
 339             } else if (n instanceof SerialWriteBarrier) {
 340                 writeBarrierSnippets.lower((SerialWriteBarrier) n, tool);
 341             } else if (n instanceof SerialArrayRangeWriteBarrier) {
 342                 writeBarrierSnippets.lower((SerialArrayRangeWriteBarrier) n, tool);
 343             } else if (n instanceof G1ArrayRangePreWriteBarrier) {
 344                 writeBarrierSnippets.lower((G1ArrayRangePreWriteBarrier) n, registers, tool);
 345             } else if (n instanceof G1ArrayRangePostWriteBarrier) {
 346                 writeBarrierSnippets.lower((G1ArrayRangePostWriteBarrier) n, registers, tool);
 347             } else if (n instanceof NewMultiArrayNode) {
 348                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 349                     newObjectSnippets.lower((NewMultiArrayNode) n, tool);
 350                 }
 351             } else if (n instanceof LoadExceptionObjectNode) {
 352                 exceptionObjectSnippets.lower((LoadExceptionObjectNode) n, registers, tool);
 353             } else if (n instanceof AssertionNode) {
 354                 assertionSnippets.lower((AssertionNode) n, tool);
 355             } else if (n instanceof StringToBytesNode) {
 356                 if (graph.getGuardsStage().areDeoptsFixed()) {
 357                     stringToBytesSnippets.lower((StringToBytesNode) n, tool);
 358                 }
 359             } else if (n instanceof IntegerDivRemNode) {
 360                 // Nothing to do for division nodes. The HotSpot signal handler catches divisions by
 361                 // zero and the MIN_VALUE / -1 cases.
 362             } else if (n instanceof AbstractDeoptimizeNode || n instanceof UnwindNode || n instanceof RemNode || n instanceof SafepointNode) {
 363                 /* No lowering, we generate LIR directly for these nodes. */
 364             } else if (n instanceof ClassGetHubNode) {
 365                 lowerClassGetHubNode((ClassGetHubNode) n, tool);
 366             } else if (n instanceof HubGetClassNode) {
 367                 lowerHubGetClassNode((HubGetClassNode) n, tool);
 368             } else if (n instanceof KlassLayoutHelperNode) {
 369                 lowerKlassLayoutHelperNode((KlassLayoutHelperNode) n, tool);
 370             } else if (n instanceof ComputeObjectAddressNode) {
 371                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 372                     lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
 373                 }
 374             } else if (n instanceof IdentityHashCodeNode) {
 375                 hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
 376             } else if (n instanceof ResolveDynamicConstantNode) {
 377                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 378                     resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
 379                 }
 380             } else if (n instanceof ResolveConstantNode) {
 381                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 382                     resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
 383                 }
 384             } else if (n instanceof ResolveMethodAndLoadCountersNode) {
 385                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 386                     resolveConstantSnippets.lower((ResolveMethodAndLoadCountersNode) n, tool);
 387                 }
 388             } else if (n instanceof InitializeKlassNode) {
 389                 if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 390                     resolveConstantSnippets.lower((InitializeKlassNode) n, tool);
 391                 }
 392             } else if (n instanceof ProfileNode) {
 393                 profileSnippets.lower((ProfileNode) n, tool);
 394             } else {
 395                 super.lower(n, tool);
 396             }
 397         }
 398     }
 399 
 400     private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
 401         /*
 402          * Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
 403          * potential safepoints and above it's uses.
 404          */
 405         for (Node use : n.usages().snapshot()) {
 406             if (use instanceof FixedNode) {
 407                 FixedNode fixed = (FixedNode) use;
 408                 StructuredGraph graph = n.graph();
 409                 GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
 410                 graph.addBeforeFixed(fixed, address);
 411                 AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
 412                 use.replaceFirstInput(n, add);
 413             } else {
 414                 throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
 415             }
 416         }
 417         GraphUtil.unlinkFixedNode(n);
 418         n.safeDelete();
 419     }
 420 
 421     private void lowerKlassLayoutHelperNode(KlassLayoutHelperNode n, LoweringTool tool) {
 422         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 423             return;
 424         }
 425         StructuredGraph graph = n.graph();
 426         assert !n.getHub().isConstant();
 427         AddressNode address = createOffsetAddress(graph, n.getHub(), runtime.getVMConfig().klassLayoutHelperOffset);
 428         n.replaceAtUsagesAndDelete(graph.unique(new FloatingReadNode(address, KLASS_LAYOUT_HELPER_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE)));
 429     }
 430 
 431     private void lowerHubGetClassNode(HubGetClassNode n, LoweringTool tool) {
 432         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 433             return;
 434         }
 435 
 436         ValueNode hub = n.getHub();
 437         GraalHotSpotVMConfig vmConfig = runtime.getVMConfig();
 438         StructuredGraph graph = n.graph();
 439         assert !hub.isConstant() || GraalOptions.ImmutableCode.getValue(graph.getOptions());
 440         AddressNode mirrorAddress = createOffsetAddress(graph, hub, vmConfig.classMirrorOffset);
 441         FloatingReadNode read = graph.unique(
 442                         new FloatingReadNode(mirrorAddress, CLASS_MIRROR_LOCATION, null, vmConfig.classMirrorIsHandle ? StampFactory.forKind(target.wordJavaKind) : n.stamp(NodeView.DEFAULT),
 443                                         null, BarrierType.NONE));
 444         if (vmConfig.classMirrorIsHandle) {
 445             AddressNode address = createOffsetAddress(graph, read, 0);
 446             read = graph.unique(new FloatingReadNode(address, CLASS_MIRROR_HANDLE_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE));
 447         }
 448         n.replaceAtUsagesAndDelete(read);
 449     }
 450 
 451     private void lowerClassGetHubNode(ClassGetHubNode n, LoweringTool tool) {
 452         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 453             return;
 454         }
 455 
 456         StructuredGraph graph = n.graph();
 457         assert !n.getValue().isConstant();
 458         AddressNode address = createOffsetAddress(graph, n.getValue(), runtime.getVMConfig().klassOffset);
 459         FloatingReadNode read = graph.unique(new FloatingReadNode(address, CLASS_KLASS_LOCATION, null, n.stamp(NodeView.DEFAULT), null, BarrierType.NONE));
 460         n.replaceAtUsagesAndDelete(read);
 461     }
 462 
 463     private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
 464         if (invoke.callTarget() instanceof MethodCallTargetNode) {
 465             MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
 466             NodeInputList<ValueNode> parameters = callTarget.arguments();
 467             ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
 468             if (!callTarget.isStatic() && receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
 469                 ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
 470                 parameters.set(0, nonNullReceiver);
 471                 receiver = nonNullReceiver;
 472             }
 473             JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
 474 
 475             LoweredCallTargetNode loweredCallTarget = null;
 476             OptionValues options = graph.getOptions();
 477             if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
 478                 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
 479                 ResolvedJavaType receiverType = invoke.getReceiverType();
 480                 if (hsMethod.isInVirtualMethodTable(receiverType)) {
 481                     JavaKind wordKind = runtime.getTarget().wordJavaKind;
 482                     ValueNode hub = createReadHub(graph, receiver, tool);
 483 
 484                     ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
 485                     // We use LocationNode.ANY_LOCATION for the reads that access the
 486                     // compiled code entry as HotSpot does not guarantee they are final
 487                     // values.
 488                     int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
 489                     AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
 490                     ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
 491 
 492                     loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 493                                     signature, callTarget.targetMethod(),
 494                                     HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
 495 
 496                     graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
 497                     graph.addAfterFixed(metaspaceMethod, compiledEntry);
 498                 }
 499             }
 500 
 501             if (loweredCallTarget == null) {
 502                 loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 503                                 signature, callTarget.targetMethod(),
 504                                 HotSpotCallingConventionType.JavaCall,
 505                                 callTarget.invokeKind()));
 506             }
 507             callTarget.replaceAndDelete(loweredCallTarget);
 508         }
 509     }
 510 
 511     private CompressEncoding getOopEncoding() {
 512         return runtime.getVMConfig().getOopEncoding();
 513     }
 514 
 515     @Override
 516     protected Stamp loadCompressedStamp(ObjectStamp stamp) {
 517         return HotSpotNarrowOopStamp.compressed(stamp, getOopEncoding());
 518     }
 519 
 520     @Override
 521     protected ValueNode newCompressionNode(CompressionOp op, ValueNode value) {
 522         return new HotSpotCompressionNode(op, value, getOopEncoding());
 523     }
 524 
 525     @Override
 526     public ValueNode staticFieldBase(StructuredGraph graph, ResolvedJavaField f) {
 527         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 528         JavaConstant base = constantReflection.asJavaClass(field.getDeclaringClass());
 529         return ConstantNode.forConstant(base, metaAccess, graph);
 530     }
 531 
 532     @Override
 533     protected ValueNode createReadArrayComponentHub(StructuredGraph graph, ValueNode arrayHub, FixedNode anchor) {
 534         /*
 535          * Anchor the read of the element klass to the cfg, because it is only valid when arrayClass
 536          * is an object class, which might not be the case in other parts of the compiled method.
 537          */
 538         AddressNode address = createOffsetAddress(graph, arrayHub, runtime.getVMConfig().arrayClassElementOffset);
 539         return graph.unique(new FloatingReadNode(address, OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION, null, KlassPointerStamp.klassNonNull(), AbstractBeginNode.prevBegin(anchor)));
 540     }
 541 
 542     @Override
 543     protected void lowerUnsafeLoadNode(RawLoadNode load, LoweringTool tool) {
 544         StructuredGraph graph = load.graph();
 545         if (!(load instanceof GuardedUnsafeLoadNode) && !graph.getGuardsStage().allowsFloatingGuards() && addReadBarrier(load)) {
 546             unsafeLoadSnippets.lower(load, tool);
 547         } else {
 548             super.lowerUnsafeLoadNode(load, tool);
 549         }
 550     }
 551 
 552     private void lowerLoadMethodNode(LoadMethodNode loadMethodNode) {
 553         StructuredGraph graph = loadMethodNode.graph();
 554         HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) loadMethodNode.getMethod();
 555         ReadNode metaspaceMethod = createReadVirtualMethod(graph, loadMethodNode.getHub(), method, loadMethodNode.getReceiverType());
 556         graph.replaceFixed(loadMethodNode, metaspaceMethod);
 557     }
 558 
 559     private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
 560         StampProvider stampProvider = tool.getStampProvider();
 561         LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
 562         HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
 563         getClass.replaceAtUsagesAndDelete(hubGetClass);
 564         hub.lower(tool);
 565         hubGetClass.lower(tool);
 566     }
 567 
 568     private void lowerStoreHubNode(StoreHubNode storeHub, StructuredGraph graph) {
 569         WriteNode hub = createWriteHub(graph, storeHub.getObject(), storeHub.getValue());
 570         graph.replaceFixed(storeHub, hub);
 571     }
 572 
 573     @Override
 574     public BarrierType fieldInitializationBarrier(JavaKind entryKind) {
 575         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.IMPRECISE : BarrierType.NONE;
 576     }
 577 
 578     @Override
 579     public BarrierType arrayInitializationBarrier(JavaKind entryKind) {
 580         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.PRECISE : BarrierType.NONE;
 581     }
 582 
 583     private void lowerOSRStartNode(OSRStartNode osrStart) {
 584         StructuredGraph graph = osrStart.graph();
 585         if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
 586             StartNode newStart = graph.add(new StartNode());
 587             ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
 588             ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
 589             migrationEnd.setStateAfter(osrStart.stateAfter());
 590             newStart.setNext(migrationEnd);
 591             FixedNode next = osrStart.next();
 592             osrStart.setNext(null);
 593             migrationEnd.setNext(next);
 594             graph.setStart(newStart);
 595 
 596             final int wordSize = target.wordSize;
 597 
 598             // @formatter:off
 599             // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
 600             // @formatter:on
 601             int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
 602             for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
 603                 int size = osrLocal.getStackKind().getSlotCount();
 604                 int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
 605                 AddressNode address = createOffsetAddress(graph, buffer, offset);
 606                 ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
 607                 osrLocal.replaceAndDelete(load);
 608                 graph.addBeforeFixed(migrationEnd, load);
 609             }
 610 
 611             // @formatter:off
 612             // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
 613             // @formatter:on
 614             final int lockCount = osrStart.stateAfter().locksSize();
 615             final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
 616 
 617             // first initialize the lock slots for all enters with the displaced marks read from the
 618             // buffer
 619             for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
 620                 MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
 621                 OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
 622                 final int index = lock.index();
 623 
 624                 final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
 625                 final int offsetLockObject = locksOffset - index * 2 * wordSize;
 626 
 627                 // load the displaced mark from the osr buffer
 628                 AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
 629                 ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
 630                 graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
 631 
 632                 // we need to initialize the stack slot for the lock
 633                 BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
 634                 graph.addBeforeFixed(migrationEnd, beginLockScope);
 635 
 636                 // write the displaced mark to the correct stack slot
 637                 AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
 638                 WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
 639                 graph.addBeforeFixed(migrationEnd, writeStackSlot);
 640 
 641                 // load the lock object from the osr buffer
 642                 AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
 643                 ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
 644                 lock.replaceAndDelete(loadObject);
 645                 graph.addBeforeFixed(migrationEnd, loadObject);
 646             }
 647 
 648             osrStart.replaceAtUsagesAndDelete(newStart);
 649         }
 650     }
 651 
 652     static final class Exceptions {
 653         protected static final EnumMap<BytecodeExceptionKind, RuntimeException> cachedExceptions;
 654 
 655         static {
 656             cachedExceptions = new EnumMap<>(BytecodeExceptionKind.class);
 657             cachedExceptions.put(BytecodeExceptionKind.NULL_POINTER, clearStackTrace(new NullPointerException()));
 658             cachedExceptions.put(BytecodeExceptionKind.OUT_OF_BOUNDS, clearStackTrace(new ArrayIndexOutOfBoundsException()));
 659             cachedExceptions.put(BytecodeExceptionKind.CLASS_CAST, clearStackTrace(new ClassCastException()));
 660             cachedExceptions.put(BytecodeExceptionKind.ARRAY_STORE, clearStackTrace(new ArrayStoreException()));
 661             cachedExceptions.put(BytecodeExceptionKind.DIVISION_BY_ZERO, clearStackTrace(new ArithmeticException()));
 662         }
 663 
 664         private static RuntimeException clearStackTrace(RuntimeException ex) {
 665             ex.setStackTrace(new StackTraceElement[0]);
 666             return ex;
 667         }
 668     }
 669 
 670     public static final class RuntimeCalls {
 671         public static final EnumMap<BytecodeExceptionKind, ForeignCallDescriptor> runtimeCalls;
 672 
 673         static {
 674             runtimeCalls = new EnumMap<>(BytecodeExceptionKind.class);
 675             runtimeCalls.put(BytecodeExceptionKind.ARRAY_STORE, new ForeignCallDescriptor("createArrayStoreException", ArrayStoreException.class, Object.class));
 676             runtimeCalls.put(BytecodeExceptionKind.CLASS_CAST, new ForeignCallDescriptor("createClassCastException", ClassCastException.class, Object.class, KlassPointer.class));
 677             runtimeCalls.put(BytecodeExceptionKind.NULL_POINTER, new ForeignCallDescriptor("createNullPointerException", NullPointerException.class));
 678             runtimeCalls.put(BytecodeExceptionKind.OUT_OF_BOUNDS, new ForeignCallDescriptor("createOutOfBoundsException", ArrayIndexOutOfBoundsException.class, int.class, int.class));
 679             runtimeCalls.put(BytecodeExceptionKind.DIVISION_BY_ZERO, new ForeignCallDescriptor("createDivisionByZeroException", ArithmeticException.class));
 680             runtimeCalls.put(BytecodeExceptionKind.INTEGER_EXACT_OVERFLOW, new ForeignCallDescriptor("createIntegerExactOverflowException", ArithmeticException.class));
 681             runtimeCalls.put(BytecodeExceptionKind.LONG_EXACT_OVERFLOW, new ForeignCallDescriptor("createLongExactOverflowException", ArithmeticException.class));
 682         }
 683     }
 684 
 685     private void throwCachedException(BytecodeExceptionNode node) {



 686         Throwable exception = Exceptions.cachedExceptions.get(node.getExceptionKind());
 687         assert exception != null;
 688 
 689         StructuredGraph graph = node.graph();
 690         FloatingNode exceptionNode = ConstantNode.forConstant(constantReflection.forObject(exception), metaAccess, graph);
 691         graph.replaceFixedWithFloating(node, exceptionNode);
 692     }
 693 
 694     private void lowerBytecodeExceptionNode(BytecodeExceptionNode node) {
 695         if (OmitHotExceptionStacktrace.getValue(node.getOptions())) {
 696             throwCachedException(node);
 697             return;
 698         }
 699 
 700         ForeignCallDescriptor descriptor = RuntimeCalls.runtimeCalls.get(node.getExceptionKind());
 701         assert descriptor != null;
 702 
 703         StructuredGraph graph = node.graph();
 704         ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(foreignCalls, descriptor, node.stamp(NodeView.DEFAULT), node.getArguments()));
 705         graph.replaceFixedWithFixed(node, foreignCallNode);
 706     }
 707 
 708     private boolean addReadBarrier(RawLoadNode load) {
 709         if (runtime.getVMConfig().useG1GC && load.graph().getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS && load.object().getStackKind() == JavaKind.Object &&
 710                         load.accessKind() == JavaKind.Object && !StampTool.isPointerAlwaysNull(load.object())) {
 711             ResolvedJavaType type = StampTool.typeOrNull(load.object());
 712             if (type != null && !type.isArray()) {
 713                 return true;
 714             }
 715         }
 716         return false;
 717     }
 718 
 719     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, HotSpotResolvedJavaMethod method, ResolvedJavaType receiverType) {
 720         return createReadVirtualMethod(graph, hub, method.vtableEntryOffset(receiverType));
 721     }
 722 
 723     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, int vtableEntryOffset) {
 724         assert vtableEntryOffset > 0;
 725         // We use LocationNode.ANY_LOCATION for the reads that access the vtable
 726         // entry as HotSpot does not guarantee that this is a final value.
 727         Stamp methodStamp = MethodPointerStamp.methodNonNull();
 728         AddressNode address = createOffsetAddress(graph, hub, vtableEntryOffset);
 729         ReadNode metaspaceMethod = graph.add(new ReadNode(address, any(), methodStamp, BarrierType.NONE));
 730         return metaspaceMethod;
 731     }
 732 
 733     @Override
 734     protected ValueNode createReadHub(StructuredGraph graph, ValueNode object, LoweringTool tool) {
 735         if (tool.getLoweringStage() != LoweringTool.StandardLoweringStage.LOW_TIER) {
 736             return graph.unique(new LoadHubNode(tool.getStampProvider(), object));
 737         }
 738         assert !object.isConstant() || object.isNullConstant();
 739 
 740         KlassPointerStamp hubStamp = KlassPointerStamp.klassNonNull();
 741         if (runtime.getVMConfig().useCompressedClassPointers) {
 742             hubStamp = hubStamp.compressed(runtime.getVMConfig().getKlassEncoding());
 743         }
 744 
 745         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 746         LocationIdentity hubLocation = runtime.getVMConfig().useCompressedClassPointers ? COMPRESSED_HUB_LOCATION : HUB_LOCATION;
 747         FloatingReadNode memoryRead = graph.unique(new FloatingReadNode(address, hubLocation, null, hubStamp, null, BarrierType.NONE));
 748         if (runtime.getVMConfig().useCompressedClassPointers) {
 749             return HotSpotCompressionNode.uncompress(memoryRead, runtime.getVMConfig().getKlassEncoding());
 750         } else {
 751             return memoryRead;
 752         }
 753     }
 754 
 755     private WriteNode createWriteHub(StructuredGraph graph, ValueNode object, ValueNode value) {
 756         assert !object.isConstant() || object.asConstant().isDefaultForKind();
 757 
 758         ValueNode writeValue = value;
 759         if (runtime.getVMConfig().useCompressedClassPointers) {
 760             writeValue = HotSpotCompressionNode.compress(value, runtime.getVMConfig().getKlassEncoding());
 761         }
 762 
 763         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 764         return graph.add(new WriteNode(address, HUB_WRITE_LOCATION, writeValue, BarrierType.NONE));
 765     }
 766 
 767     @Override
 768     protected BarrierType fieldLoadBarrierType(ResolvedJavaField f) {
 769         HotSpotResolvedJavaField loadField = (HotSpotResolvedJavaField) f;
 770         BarrierType barrierType = BarrierType.NONE;
 771         if (runtime.getVMConfig().useG1GC && loadField.getJavaKind() == JavaKind.Object && metaAccess.lookupJavaType(Reference.class).equals(loadField.getDeclaringClass()) &&
 772                         loadField.getName().equals("referent")) {
 773             barrierType = BarrierType.PRECISE;
 774         }
 775         return barrierType;
 776     }
 777 
 778     @Override
 779     public int fieldOffset(ResolvedJavaField f) {
 780         return f.getOffset();
 781     }
 782 
 783     @Override
 784     public int arrayLengthOffset() {
 785         return runtime.getVMConfig().arrayOopDescLengthOffset();
 786     }
 787 
 788     @Override
 789     protected final JavaKind getStorageKind(ResolvedJavaField field) {
 790         return field.getJavaKind();
 791     }
 792 
 793     @Override
 794     public ObjectCloneSnippets.Templates getObjectCloneSnippets() {
 795         return objectCloneSnippets;
 796     }
 797 
 798     @Override
 799     public ForeignCallSnippets.Templates getForeignCallSnippets() {
 800         return foreignCallSnippets;
 801     }
 802 }
--- EOF ---