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_HANDLE_LOCATION;
  32 import static org.graalvm.compiler.hotspot.replacements.HotSpotReplacementsUtil.CLASS_MIRROR_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.CompressEncoding;
  45 import org.graalvm.compiler.core.common.GraalOptions;
  46 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  47 import org.graalvm.compiler.core.common.spi.ForeignCallsProvider;
  48 import org.graalvm.compiler.core.common.type.ObjectStamp;
  49 import org.graalvm.compiler.core.common.type.Stamp;
  50 import org.graalvm.compiler.core.common.type.StampFactory;
  51 import org.graalvm.compiler.core.common.type.StampPair;
  52 import org.graalvm.compiler.debug.DebugHandlersFactory;
  53 import org.graalvm.compiler.debug.GraalError;
  54 import org.graalvm.compiler.graph.Node;
  55 import org.graalvm.compiler.graph.NodeInputList;
  56 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
  57 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
  58 import org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode;
  59 import org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode;
  60 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier;
  61 import org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier;
  62 import org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier;
  63 import org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier;
  64 import org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier;
  65 import org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode;
  66 import org.graalvm.compiler.hotspot.nodes.HotSpotCompressionNode;
  67 import org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode;
  68 import org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode;
  69 import org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier;
  70 import org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier;
  71 import org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode;
  72 import org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode;
  73 import org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode;
  74 import org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode;
  75 import org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode;
  76 import org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp;
  77 import org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp;
  78 import org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp;
  79 import org.graalvm.compiler.hotspot.replacements.AssertionSnippets;
  80 import org.graalvm.compiler.hotspot.replacements.ClassGetHubNode;
  81 import org.graalvm.compiler.hotspot.replacements.HashCodeSnippets;
  82 import org.graalvm.compiler.hotspot.replacements.HubGetClassNode;
  83 import org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode;
  84 import org.graalvm.compiler.hotspot.replacements.InstanceOfSnippets;
  85 import org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode;
  86 import org.graalvm.compiler.hotspot.replacements.LoadExceptionObjectSnippets;
  87 import org.graalvm.compiler.hotspot.replacements.MonitorSnippets;
  88 import org.graalvm.compiler.hotspot.replacements.NewObjectSnippets;
  89 import org.graalvm.compiler.hotspot.replacements.StringToBytesSnippets;
  90 import org.graalvm.compiler.hotspot.replacements.UnsafeLoadSnippets;
  91 import org.graalvm.compiler.hotspot.replacements.WriteBarrierSnippets;
  92 import org.graalvm.compiler.hotspot.replacements.aot.ResolveConstantSnippets;
  93 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyNode;
  94 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyWithSlowPathNode;
  95 import org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopySnippets;
  96 import org.graalvm.compiler.hotspot.replacements.profiling.ProfileSnippets;
  97 import org.graalvm.compiler.hotspot.word.KlassPointer;
  98 import org.graalvm.compiler.nodes.AbstractBeginNode;
  99 import org.graalvm.compiler.nodes.AbstractDeoptimizeNode;
 100 import org.graalvm.compiler.nodes.CompressionNode.CompressionOp;
 101 import org.graalvm.compiler.nodes.ConstantNode;
 102 import org.graalvm.compiler.nodes.FixedNode;
 103 import org.graalvm.compiler.nodes.Invoke;
 104 import org.graalvm.compiler.nodes.LogicNode;
 105 import org.graalvm.compiler.nodes.LoweredCallTargetNode;
 106 import org.graalvm.compiler.nodes.ParameterNode;
 107 import org.graalvm.compiler.nodes.SafepointNode;
 108 import org.graalvm.compiler.nodes.StartNode;
 109 import org.graalvm.compiler.nodes.StructuredGraph;
 110 import org.graalvm.compiler.nodes.UnwindNode;
 111 import org.graalvm.compiler.nodes.ValueNode;
 112 import org.graalvm.compiler.nodes.calc.AddNode;
 113 import org.graalvm.compiler.nodes.calc.FloatingNode;
 114 import org.graalvm.compiler.nodes.calc.IntegerDivRemNode;
 115 import org.graalvm.compiler.nodes.calc.IsNullNode;
 116 import org.graalvm.compiler.nodes.calc.RemNode;
 117 import org.graalvm.compiler.nodes.debug.StringToBytesNode;
 118 import org.graalvm.compiler.nodes.debug.VerifyHeapNode;
 119 import org.graalvm.compiler.nodes.extended.BytecodeExceptionNode;
 120 import org.graalvm.compiler.nodes.extended.ForeignCallNode;
 121 import org.graalvm.compiler.nodes.extended.GetClassNode;
 122 import org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode;
 123 import org.graalvm.compiler.nodes.extended.LoadHubNode;
 124 import org.graalvm.compiler.nodes.extended.LoadMethodNode;
 125 import org.graalvm.compiler.nodes.extended.OSRLocalNode;
 126 import org.graalvm.compiler.nodes.extended.OSRLockNode;
 127 import org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode;
 128 import org.graalvm.compiler.nodes.extended.OSRStartNode;
 129 import org.graalvm.compiler.nodes.extended.RawLoadNode;
 130 import org.graalvm.compiler.nodes.extended.StoreHubNode;
 131 import org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode;
 132 import org.graalvm.compiler.nodes.java.DynamicNewArrayNode;
 133 import org.graalvm.compiler.nodes.java.DynamicNewInstanceNode;
 134 import org.graalvm.compiler.nodes.java.InstanceOfDynamicNode;
 135 import org.graalvm.compiler.nodes.java.InstanceOfNode;
 136 import org.graalvm.compiler.nodes.java.LoadExceptionObjectNode;
 137 import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
 138 import org.graalvm.compiler.nodes.java.MonitorExitNode;
 139 import org.graalvm.compiler.nodes.java.MonitorIdNode;
 140 import org.graalvm.compiler.nodes.java.NewArrayNode;
 141 import org.graalvm.compiler.nodes.java.NewInstanceNode;
 142 import org.graalvm.compiler.nodes.java.NewMultiArrayNode;
 143 import org.graalvm.compiler.nodes.java.RawMonitorEnterNode;
 144 import org.graalvm.compiler.nodes.memory.FloatingReadNode;
 145 import org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType;
 146 import org.graalvm.compiler.nodes.memory.ReadNode;
 147 import org.graalvm.compiler.nodes.memory.WriteNode;
 148 import org.graalvm.compiler.nodes.memory.address.AddressNode;
 149 import org.graalvm.compiler.nodes.spi.LoweringProvider;
 150 import org.graalvm.compiler.nodes.spi.LoweringTool;
 151 import org.graalvm.compiler.nodes.spi.StampProvider;
 152 import org.graalvm.compiler.nodes.type.StampTool;
 153 import org.graalvm.compiler.nodes.util.GraphUtil;
 154 import org.graalvm.compiler.options.OptionValues;
 155 import org.graalvm.compiler.replacements.DefaultJavaLoweringProvider;
 156 import org.graalvm.compiler.replacements.nodes.AssertionNode;
 157 import org.graalvm.word.LocationIdentity;
 158 
 159 import jdk.vm.ci.code.TargetDescription;
 160 import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
 161 import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
 162 import jdk.vm.ci.hotspot.HotSpotResolvedJavaField;
 163 import jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod;
 164 import jdk.vm.ci.meta.JavaConstant;
 165 import jdk.vm.ci.meta.JavaKind;
 166 import jdk.vm.ci.meta.JavaType;
 167 import jdk.vm.ci.meta.MetaAccessProvider;
 168 import jdk.vm.ci.meta.ResolvedJavaField;
 169 import jdk.vm.ci.meta.ResolvedJavaType;
 170 
 171 /**
 172  * HotSpot implementation of {@link LoweringProvider}.
 173  */
 174 public class DefaultHotSpotLoweringProvider extends DefaultJavaLoweringProvider implements HotSpotLoweringProvider {
 175 
 176     protected final HotSpotGraalRuntimeProvider runtime;
 177     protected final HotSpotRegistersProvider registers;
 178     protected final HotSpotConstantReflectionProvider constantReflection;
 179 
 180     protected InstanceOfSnippets.Templates instanceofSnippets;
 181     protected NewObjectSnippets.Templates newObjectSnippets;
 182     protected MonitorSnippets.Templates monitorSnippets;
 183     protected WriteBarrierSnippets.Templates writeBarrierSnippets;
 184     protected LoadExceptionObjectSnippets.Templates exceptionObjectSnippets;
 185     protected UnsafeLoadSnippets.Templates unsafeLoadSnippets;
 186     protected AssertionSnippets.Templates assertionSnippets;
 187     protected ArrayCopySnippets.Templates arraycopySnippets;
 188     protected StringToBytesSnippets.Templates stringToBytesSnippets;
 189     protected HashCodeSnippets.Templates hashCodeSnippets;
 190     protected ResolveConstantSnippets.Templates resolveConstantSnippets;
 191     protected ProfileSnippets.Templates profileSnippets;
 192 
 193     public DefaultHotSpotLoweringProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, ForeignCallsProvider foreignCalls, HotSpotRegistersProvider registers,
 194                     HotSpotConstantReflectionProvider constantReflection, TargetDescription target) {
 195         super(metaAccess, foreignCalls, target, runtime.getVMConfig().useCompressedOops);
 196         this.runtime = runtime;
 197         this.registers = registers;
 198         this.constantReflection = constantReflection;
 199     }
 200 
 201     @Override
 202     public void initialize(OptionValues options, Iterable<DebugHandlersFactory> factories, HotSpotProviders providers, GraalHotSpotVMConfig config) {
 203         super.initialize(options, factories, runtime, providers, providers.getSnippetReflection());
 204 
 205         assert target == providers.getCodeCache().getTarget();
 206         instanceofSnippets = new InstanceOfSnippets.Templates(options, factories, runtime, providers, target);
 207         newObjectSnippets = new NewObjectSnippets.Templates(options, factories, runtime, providers, target, config);
 208         monitorSnippets = new MonitorSnippets.Templates(options, factories, runtime, providers, target, config.useFastLocking);
 209         writeBarrierSnippets = new WriteBarrierSnippets.Templates(options, factories, runtime, providers, target, config.useCompressedOops ? config.getOopEncoding() : null);
 210         exceptionObjectSnippets = new LoadExceptionObjectSnippets.Templates(options, factories, providers, target);
 211         unsafeLoadSnippets = new UnsafeLoadSnippets.Templates(options, factories, providers, target);
 212         assertionSnippets = new AssertionSnippets.Templates(options, factories, providers, target);
 213         arraycopySnippets = new ArrayCopySnippets.Templates(options, factories, runtime, providers, target);
 214         stringToBytesSnippets = new StringToBytesSnippets.Templates(options, factories, providers, target);
 215         hashCodeSnippets = new HashCodeSnippets.Templates(options, factories, providers, target);
 216         resolveConstantSnippets = new ResolveConstantSnippets.Templates(options, factories, providers, target);
 217         profileSnippets = new ProfileSnippets.Templates(options, factories, providers, target);
 218     }
 219 
 220     public MonitorSnippets.Templates getMonitorSnippets() {
 221         return monitorSnippets;
 222     }
 223 
 224     @Override
 225     public void lower(Node n, LoweringTool tool) {
 226         StructuredGraph graph = (StructuredGraph) n.graph();
 227         if (n instanceof Invoke) {
 228             lowerInvoke((Invoke) n, tool, graph);
 229         } else if (n instanceof LoadMethodNode) {
 230             lowerLoadMethodNode((LoadMethodNode) n);
 231         } else if (n instanceof GetClassNode) {
 232             lowerGetClassNode((GetClassNode) n, tool, graph);
 233         } else if (n instanceof StoreHubNode) {
 234             lowerStoreHubNode((StoreHubNode) n, graph);
 235         } else if (n instanceof OSRStartNode) {
 236             lowerOSRStartNode((OSRStartNode) n);
 237         } else if (n instanceof BytecodeExceptionNode) {
 238             lowerBytecodeExceptionNode((BytecodeExceptionNode) n);
 239         } else if (n instanceof InstanceOfNode) {
 240             InstanceOfNode instanceOfNode = (InstanceOfNode) n;
 241             if (graph.getGuardsStage().areDeoptsFixed()) {
 242                 instanceofSnippets.lower(instanceOfNode, tool);
 243             } else {
 244                 if (instanceOfNode.allowsNull()) {
 245                     ValueNode object = instanceOfNode.getValue();
 246                     LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfNode.create(instanceOfNode.type(), object, instanceOfNode.profile(), instanceOfNode.getAnchor()));
 247                     LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 248                     instanceOfNode.replaceAndDelete(newNode);
 249                 }
 250             }
 251         } else if (n instanceof InstanceOfDynamicNode) {
 252             InstanceOfDynamicNode instanceOfDynamicNode = (InstanceOfDynamicNode) n;
 253             if (graph.getGuardsStage().areDeoptsFixed()) {
 254                 instanceofSnippets.lower(instanceOfDynamicNode, tool);
 255             } else {
 256                 ValueNode mirror = instanceOfDynamicNode.getMirrorOrHub();
 257                 if (mirror.stamp().getStackKind() == JavaKind.Object) {
 258                     ClassGetHubNode classGetHub = graph.unique(new ClassGetHubNode(mirror));
 259                     instanceOfDynamicNode.setMirror(classGetHub);
 260                 }
 261 
 262                 if (instanceOfDynamicNode.allowsNull()) {
 263                     ValueNode object = instanceOfDynamicNode.getObject();
 264                     LogicNode newTypeCheck = graph.addOrUniqueWithInputs(
 265                                     InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), instanceOfDynamicNode.getMirrorOrHub(), object, false));
 266                     LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
 267                     instanceOfDynamicNode.replaceAndDelete(newNode);
 268                 }
 269             }
 270         } else if (n instanceof ClassIsAssignableFromNode) {
 271             if (graph.getGuardsStage().areDeoptsFixed()) {
 272                 instanceofSnippets.lower((ClassIsAssignableFromNode) n, tool);
 273             }
 274         } else if (n instanceof NewInstanceNode) {
 275             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 276                 newObjectSnippets.lower((NewInstanceNode) n, registers, tool);
 277             }
 278         } else if (n instanceof DynamicNewInstanceNode) {
 279             DynamicNewInstanceNode newInstanceNode = (DynamicNewInstanceNode) n;
 280             if (newInstanceNode.getClassClass() == null) {
 281                 JavaConstant classClassMirror = constantReflection.forObject(Class.class);
 282                 ConstantNode classClass = ConstantNode.forConstant(classClassMirror, tool.getMetaAccess(), graph);
 283                 newInstanceNode.setClassClass(classClass);
 284             }
 285             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 286                 newObjectSnippets.lower(newInstanceNode, registers, tool);
 287             }
 288         } else if (n instanceof NewArrayNode) {
 289             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 290                 newObjectSnippets.lower((NewArrayNode) n, registers, tool);
 291             }
 292         } else if (n instanceof DynamicNewArrayNode) {
 293             DynamicNewArrayNode dynamicNewArrayNode = (DynamicNewArrayNode) n;
 294             if (dynamicNewArrayNode.getVoidClass() == null) {
 295                 JavaConstant voidClassMirror = constantReflection.forObject(void.class);
 296                 ConstantNode voidClass = ConstantNode.forConstant(voidClassMirror, tool.getMetaAccess(), graph);
 297                 dynamicNewArrayNode.setVoidClass(voidClass);
 298             }
 299             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 300                 newObjectSnippets.lower(dynamicNewArrayNode, registers, tool);
 301             }
 302         } else if (n instanceof VerifyHeapNode) {
 303             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 304                 newObjectSnippets.lower((VerifyHeapNode) n, registers, tool);
 305             }
 306         } else if (n instanceof RawMonitorEnterNode) {
 307             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 308                 monitorSnippets.lower((RawMonitorEnterNode) n, registers, tool);
 309             }
 310         } else if (n instanceof MonitorExitNode) {
 311             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 312                 monitorSnippets.lower((MonitorExitNode) n, registers, tool);
 313             }
 314         } else if (n instanceof ArrayCopyNode) {
 315             arraycopySnippets.lower((ArrayCopyNode) n, tool);
 316         } else if (n instanceof ArrayCopyWithSlowPathNode) {
 317             arraycopySnippets.lower((ArrayCopyWithSlowPathNode) n, tool);
 318         } else if (n instanceof G1PreWriteBarrier) {
 319             writeBarrierSnippets.lower((G1PreWriteBarrier) n, registers, tool);
 320         } else if (n instanceof G1PostWriteBarrier) {
 321             writeBarrierSnippets.lower((G1PostWriteBarrier) n, registers, tool);
 322         } else if (n instanceof G1ReferentFieldReadBarrier) {
 323             writeBarrierSnippets.lower((G1ReferentFieldReadBarrier) n, registers, tool);
 324         } else if (n instanceof SerialWriteBarrier) {
 325             writeBarrierSnippets.lower((SerialWriteBarrier) n, tool);
 326         } else if (n instanceof SerialArrayRangeWriteBarrier) {
 327             writeBarrierSnippets.lower((SerialArrayRangeWriteBarrier) n, tool);
 328         } else if (n instanceof G1ArrayRangePreWriteBarrier) {
 329             writeBarrierSnippets.lower((G1ArrayRangePreWriteBarrier) n, registers, tool);
 330         } else if (n instanceof G1ArrayRangePostWriteBarrier) {
 331             writeBarrierSnippets.lower((G1ArrayRangePostWriteBarrier) n, registers, tool);
 332         } else if (n instanceof NewMultiArrayNode) {
 333             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 334                 newObjectSnippets.lower((NewMultiArrayNode) n, tool);
 335             }
 336         } else if (n instanceof LoadExceptionObjectNode) {
 337             exceptionObjectSnippets.lower((LoadExceptionObjectNode) n, registers, tool);
 338         } else if (n instanceof AssertionNode) {
 339             assertionSnippets.lower((AssertionNode) n, tool);
 340         } else if (n instanceof StringToBytesNode) {
 341             if (graph.getGuardsStage().areDeoptsFixed()) {
 342                 stringToBytesSnippets.lower((StringToBytesNode) n, tool);
 343             }
 344         } else if (n instanceof IntegerDivRemNode) {
 345             // Nothing to do for division nodes. The HotSpot signal handler catches divisions by
 346             // zero and the MIN_VALUE / -1 cases.
 347         } else if (n instanceof AbstractDeoptimizeNode || n instanceof UnwindNode || n instanceof RemNode || n instanceof SafepointNode) {
 348             /* No lowering, we generate LIR directly for these nodes. */
 349         } else if (n instanceof ClassGetHubNode) {
 350             lowerClassGetHubNode((ClassGetHubNode) n, tool);
 351         } else if (n instanceof HubGetClassNode) {
 352             lowerHubGetClassNode((HubGetClassNode) n, tool);
 353         } else if (n instanceof KlassLayoutHelperNode) {
 354             lowerKlassLayoutHelperNode((KlassLayoutHelperNode) n, tool);
 355         } else if (n instanceof ComputeObjectAddressNode) {
 356             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 357                 lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
 358             }
 359         } else if (n instanceof IdentityHashCodeNode) {
 360             hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
 361         } else if (n instanceof ResolveDynamicConstantNode) {
 362             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 363                 resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
 364             }
 365         } else if (n instanceof ResolveConstantNode) {
 366             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 367                 resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
 368             }
 369         } else if (n instanceof ResolveMethodAndLoadCountersNode) {
 370             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 371                 resolveConstantSnippets.lower((ResolveMethodAndLoadCountersNode) n, tool);
 372             }
 373         } else if (n instanceof InitializeKlassNode) {
 374             if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
 375                 resolveConstantSnippets.lower((InitializeKlassNode) n, tool);
 376             }
 377         } else if (n instanceof ProfileNode) {
 378             profileSnippets.lower((ProfileNode) n, tool);
 379         } else {
 380             super.lower(n, tool);
 381         }
 382     }
 383 
 384     private static void lowerComputeObjectAddressNode(ComputeObjectAddressNode n) {
 385         /*
 386          * Lower the node into a ComputeObjectAddress node and an Add but ensure that it's below any
 387          * potential safepoints and above it's uses.
 388          */
 389         for (Node use : n.usages().snapshot()) {
 390             if (use instanceof FixedNode) {
 391                 FixedNode fixed = (FixedNode) use;
 392                 StructuredGraph graph = n.graph();
 393                 GetObjectAddressNode address = graph.add(new GetObjectAddressNode(n.getObject()));
 394                 graph.addBeforeFixed(fixed, address);
 395                 AddNode add = graph.addOrUnique(new AddNode(address, n.getOffset()));
 396                 use.replaceFirstInput(n, add);
 397             } else {
 398                 throw GraalError.shouldNotReachHere("Unexpected floating use of ComputeObjectAddressNode " + n);
 399             }
 400         }
 401         GraphUtil.unlinkFixedNode(n);
 402         n.safeDelete();
 403     }
 404 
 405     private void lowerKlassLayoutHelperNode(KlassLayoutHelperNode n, LoweringTool tool) {
 406         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 407             return;
 408         }
 409         StructuredGraph graph = n.graph();
 410         assert !n.getHub().isConstant();
 411         AddressNode address = createOffsetAddress(graph, n.getHub(), runtime.getVMConfig().klassLayoutHelperOffset);
 412         n.replaceAtUsagesAndDelete(graph.unique(new FloatingReadNode(address, KLASS_LAYOUT_HELPER_LOCATION, null, n.stamp(), null, BarrierType.NONE)));
 413     }
 414 
 415     private void lowerHubGetClassNode(HubGetClassNode n, LoweringTool tool) {
 416         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 417             return;
 418         }
 419 
 420         ValueNode hub = n.getHub();
 421         GraalHotSpotVMConfig vmConfig = runtime.getVMConfig();
 422         StructuredGraph graph = n.graph();
 423         assert !hub.isConstant() || GraalOptions.ImmutableCode.getValue(graph.getOptions());
 424         AddressNode mirrorAddress = createOffsetAddress(graph, hub, vmConfig.classMirrorOffset);
 425         FloatingReadNode read = graph.unique(new FloatingReadNode(mirrorAddress, CLASS_MIRROR_LOCATION, null, vmConfig.classMirrorIsHandle ? StampFactory.forKind(target.wordJavaKind) : n.stamp(),
 426                         null, BarrierType.NONE));
 427         if (vmConfig.classMirrorIsHandle) {
 428             AddressNode address = createOffsetAddress(graph, read, 0);
 429             read = graph.unique(new FloatingReadNode(address, CLASS_MIRROR_HANDLE_LOCATION, null, n.stamp(), null, BarrierType.NONE));
 430         }
 431         n.replaceAtUsagesAndDelete(read);
 432     }
 433 
 434     private void lowerClassGetHubNode(ClassGetHubNode n, LoweringTool tool) {
 435         if (tool.getLoweringStage() == LoweringTool.StandardLoweringStage.HIGH_TIER) {
 436             return;
 437         }
 438 
 439         StructuredGraph graph = n.graph();
 440         assert !n.getValue().isConstant();
 441         AddressNode address = createOffsetAddress(graph, n.getValue(), runtime.getVMConfig().klassOffset);
 442         FloatingReadNode read = graph.unique(new FloatingReadNode(address, CLASS_KLASS_LOCATION, null, n.stamp(), null, BarrierType.NONE));
 443         n.replaceAtUsagesAndDelete(read);
 444     }
 445 
 446     private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
 447         if (invoke.callTarget() instanceof MethodCallTargetNode) {
 448             MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
 449             NodeInputList<ValueNode> parameters = callTarget.arguments();
 450             ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
 451             if (!callTarget.isStatic() && receiver.stamp() instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
 452                 ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
 453                 parameters.set(0, nonNullReceiver);
 454                 receiver = nonNullReceiver;
 455             }
 456             JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
 457 
 458             LoweredCallTargetNode loweredCallTarget = null;
 459             OptionValues options = graph.getOptions();
 460             if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
 461                 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
 462                 ResolvedJavaType receiverType = invoke.getReceiverType();
 463                 if (hsMethod.isInVirtualMethodTable(receiverType)) {
 464                     JavaKind wordKind = runtime.getTarget().wordJavaKind;
 465                     ValueNode hub = createReadHub(graph, receiver, tool);
 466 
 467                     ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
 468                     // We use LocationNode.ANY_LOCATION for the reads that access the
 469                     // compiled code entry as HotSpot does not guarantee they are final
 470                     // values.
 471                     int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
 472                     AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
 473                     ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
 474 
 475                     loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 476                                     signature, callTarget.targetMethod(),
 477                                     HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
 478 
 479                     graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
 480                     graph.addAfterFixed(metaspaceMethod, compiledEntry);
 481                 }
 482             }
 483 
 484             if (loweredCallTarget == null) {
 485                 loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(),
 486                                 signature, callTarget.targetMethod(),
 487                                 HotSpotCallingConventionType.JavaCall,
 488                                 callTarget.invokeKind()));
 489             }
 490             callTarget.replaceAndDelete(loweredCallTarget);
 491         }
 492     }
 493 
 494     private CompressEncoding getOopEncoding() {
 495         return runtime.getVMConfig().getOopEncoding();
 496     }
 497 
 498     @Override
 499     protected Stamp loadCompressedStamp(ObjectStamp stamp) {
 500         return HotSpotNarrowOopStamp.compressed(stamp, getOopEncoding());
 501     }
 502 
 503     @Override
 504     protected ValueNode newCompressionNode(CompressionOp op, ValueNode value) {
 505         return new HotSpotCompressionNode(op, value, getOopEncoding());
 506     }
 507 
 508     @Override
 509     public ValueNode staticFieldBase(StructuredGraph graph, ResolvedJavaField f) {
 510         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 511         JavaConstant base = constantReflection.asJavaClass(field.getDeclaringClass());
 512         return ConstantNode.forConstant(base, metaAccess, graph);
 513     }
 514 
 515     @Override
 516     protected ValueNode createReadArrayComponentHub(StructuredGraph graph, ValueNode arrayHub, FixedNode anchor) {
 517         /*
 518          * Anchor the read of the element klass to the cfg, because it is only valid when arrayClass
 519          * is an object class, which might not be the case in other parts of the compiled method.
 520          */
 521         AddressNode address = createOffsetAddress(graph, arrayHub, runtime.getVMConfig().arrayClassElementOffset);
 522         return graph.unique(new FloatingReadNode(address, OBJ_ARRAY_KLASS_ELEMENT_KLASS_LOCATION, null, KlassPointerStamp.klassNonNull(), AbstractBeginNode.prevBegin(anchor)));
 523     }
 524 
 525     @Override
 526     protected void lowerUnsafeLoadNode(RawLoadNode load, LoweringTool tool) {
 527         StructuredGraph graph = load.graph();
 528         if (!(load instanceof GuardedUnsafeLoadNode) && !graph.getGuardsStage().allowsFloatingGuards() && addReadBarrier(load)) {
 529             unsafeLoadSnippets.lower(load, tool);
 530         } else {
 531             super.lowerUnsafeLoadNode(load, tool);
 532         }
 533     }
 534 
 535     private void lowerLoadMethodNode(LoadMethodNode loadMethodNode) {
 536         StructuredGraph graph = loadMethodNode.graph();
 537         HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) loadMethodNode.getMethod();
 538         ReadNode metaspaceMethod = createReadVirtualMethod(graph, loadMethodNode.getHub(), method, loadMethodNode.getReceiverType());
 539         graph.replaceFixed(loadMethodNode, metaspaceMethod);
 540     }
 541 
 542     private static void lowerGetClassNode(GetClassNode getClass, LoweringTool tool, StructuredGraph graph) {
 543         StampProvider stampProvider = tool.getStampProvider();
 544         LoadHubNode hub = graph.unique(new LoadHubNode(stampProvider, getClass.getObject()));
 545         HubGetClassNode hubGetClass = graph.unique(new HubGetClassNode(tool.getMetaAccess(), hub));
 546         getClass.replaceAtUsagesAndDelete(hubGetClass);
 547         hub.lower(tool);
 548         hubGetClass.lower(tool);
 549     }
 550 
 551     private void lowerStoreHubNode(StoreHubNode storeHub, StructuredGraph graph) {
 552         WriteNode hub = createWriteHub(graph, storeHub.getObject(), storeHub.getValue());
 553         graph.replaceFixed(storeHub, hub);
 554     }
 555 
 556     @Override
 557     public BarrierType fieldInitializationBarrier(JavaKind entryKind) {
 558         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.IMPRECISE : BarrierType.NONE;
 559     }
 560 
 561     @Override
 562     public BarrierType arrayInitializationBarrier(JavaKind entryKind) {
 563         return (entryKind == JavaKind.Object && !runtime.getVMConfig().useDeferredInitBarriers) ? BarrierType.PRECISE : BarrierType.NONE;
 564     }
 565 
 566     private void lowerOSRStartNode(OSRStartNode osrStart) {
 567         StructuredGraph graph = osrStart.graph();
 568         if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
 569             StartNode newStart = graph.add(new StartNode());
 570             ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
 571             ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
 572             migrationEnd.setStateAfter(osrStart.stateAfter());
 573             newStart.setNext(migrationEnd);
 574             FixedNode next = osrStart.next();
 575             osrStart.setNext(null);
 576             migrationEnd.setNext(next);
 577             graph.setStart(newStart);
 578 
 579             final int wordSize = target.wordSize;
 580 
 581             // @formatter:off
 582             // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
 583             // @formatter:on
 584             int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
 585             for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
 586                 int size = osrLocal.getStackKind().getSlotCount();
 587                 int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
 588                 AddressNode address = createOffsetAddress(graph, buffer, offset);
 589                 ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(), BarrierType.NONE));
 590                 osrLocal.replaceAndDelete(load);
 591                 graph.addBeforeFixed(migrationEnd, load);
 592             }
 593 
 594             // @formatter:off
 595             // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
 596             // @formatter:on
 597             final int lockCount = osrStart.stateAfter().locksSize();
 598             final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
 599 
 600             // first initialize the lock slots for all enters with the displaced marks read from the
 601             // buffer
 602             for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
 603                 MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
 604                 OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
 605                 final int index = lock.index();
 606 
 607                 final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
 608                 final int offsetLockObject = locksOffset - index * 2 * wordSize;
 609 
 610                 // load the displaced mark from the osr buffer
 611                 AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
 612                 ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(), BarrierType.NONE));
 613                 graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
 614 
 615                 // we need to initialize the stack slot for the lock
 616                 BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
 617                 graph.addBeforeFixed(migrationEnd, beginLockScope);
 618 
 619                 // write the displaced mark to the correct stack slot
 620                 AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
 621                 WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
 622                 graph.addBeforeFixed(migrationEnd, writeStackSlot);
 623 
 624                 // load the lock object from the osr buffer
 625                 AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
 626                 ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(), BarrierType.NONE));
 627                 lock.replaceAndDelete(loadObject);
 628                 graph.addBeforeFixed(migrationEnd, loadObject);
 629             }
 630 
 631             osrStart.replaceAtUsagesAndDelete(newStart);
 632         }
 633     }
 634 
 635     static final class Exceptions {
 636         protected static final ArrayIndexOutOfBoundsException cachedArrayIndexOutOfBoundsException;
 637         protected static final NullPointerException cachedNullPointerException;
 638 
 639         static {
 640             cachedArrayIndexOutOfBoundsException = new ArrayIndexOutOfBoundsException();
 641             cachedArrayIndexOutOfBoundsException.setStackTrace(new StackTraceElement[0]);
 642             cachedNullPointerException = new NullPointerException();
 643             cachedNullPointerException.setStackTrace(new StackTraceElement[0]);
 644         }
 645     }
 646 
 647     public static final class RuntimeCalls {
 648         public static final ForeignCallDescriptor CREATE_ARRAY_STORE_EXCEPTION = new ForeignCallDescriptor("createArrayStoreException", ArrayStoreException.class, Object.class);
 649         public static final ForeignCallDescriptor CREATE_CLASS_CAST_EXCEPTION = new ForeignCallDescriptor("createClassCastException", ClassCastException.class, Object.class, KlassPointer.class);
 650         public static final ForeignCallDescriptor CREATE_NULL_POINTER_EXCEPTION = new ForeignCallDescriptor("createNullPointerException", NullPointerException.class);
 651         public static final ForeignCallDescriptor CREATE_OUT_OF_BOUNDS_EXCEPTION = new ForeignCallDescriptor("createOutOfBoundsException", ArrayIndexOutOfBoundsException.class, int.class);
 652     }
 653 
 654     private boolean throwCachedException(BytecodeExceptionNode node) {
 655         Throwable exception;
 656         if (node.getExceptionClass() == NullPointerException.class) {
 657             exception = Exceptions.cachedNullPointerException;
 658         } else if (node.getExceptionClass() == ArrayIndexOutOfBoundsException.class) {
 659             exception = Exceptions.cachedArrayIndexOutOfBoundsException;
 660         } else {
 661             return false;
 662         }
 663 
 664         StructuredGraph graph = node.graph();
 665         FloatingNode exceptionNode = ConstantNode.forConstant(constantReflection.forObject(exception), metaAccess, graph);
 666         graph.replaceFixedWithFloating(node, exceptionNode);
 667         return true;
 668     }
 669 
 670     private void lowerBytecodeExceptionNode(BytecodeExceptionNode node) {
 671         if (OmitHotExceptionStacktrace.getValue(node.getOptions())) {
 672             if (throwCachedException(node)) {
 673                 return;
 674             }
 675         }
 676 
 677         ForeignCallDescriptor descriptor;
 678         if (node.getExceptionClass() == NullPointerException.class) {
 679             descriptor = RuntimeCalls.CREATE_NULL_POINTER_EXCEPTION;
 680         } else if (node.getExceptionClass() == ArrayIndexOutOfBoundsException.class) {
 681             descriptor = RuntimeCalls.CREATE_OUT_OF_BOUNDS_EXCEPTION;
 682         } else if (node.getExceptionClass() == ArrayStoreException.class) {
 683             descriptor = RuntimeCalls.CREATE_ARRAY_STORE_EXCEPTION;
 684         } else if (node.getExceptionClass() == ClassCastException.class) {
 685             descriptor = RuntimeCalls.CREATE_CLASS_CAST_EXCEPTION;
 686         } else {
 687             throw GraalError.shouldNotReachHere();
 688         }
 689 
 690         StructuredGraph graph = node.graph();
 691         ForeignCallNode foreignCallNode = graph.add(new ForeignCallNode(foreignCalls, descriptor, node.stamp(), node.getArguments()));
 692         graph.replaceFixedWithFixed(node, foreignCallNode);
 693     }
 694 
 695     private boolean addReadBarrier(RawLoadNode load) {
 696         if (runtime.getVMConfig().useG1GC && load.graph().getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS && load.object().getStackKind() == JavaKind.Object &&
 697                         load.accessKind() == JavaKind.Object && !StampTool.isPointerAlwaysNull(load.object())) {
 698             ResolvedJavaType type = StampTool.typeOrNull(load.object());
 699             if (type != null && !type.isArray()) {
 700                 return true;
 701             }
 702         }
 703         return false;
 704     }
 705 
 706     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, HotSpotResolvedJavaMethod method, ResolvedJavaType receiverType) {
 707         return createReadVirtualMethod(graph, hub, method.vtableEntryOffset(receiverType));
 708     }
 709 
 710     private ReadNode createReadVirtualMethod(StructuredGraph graph, ValueNode hub, int vtableEntryOffset) {
 711         assert vtableEntryOffset > 0;
 712         // We use LocationNode.ANY_LOCATION for the reads that access the vtable
 713         // entry as HotSpot does not guarantee that this is a final value.
 714         Stamp methodStamp = MethodPointerStamp.methodNonNull();
 715         AddressNode address = createOffsetAddress(graph, hub, vtableEntryOffset);
 716         ReadNode metaspaceMethod = graph.add(new ReadNode(address, any(), methodStamp, BarrierType.NONE));
 717         return metaspaceMethod;
 718     }
 719 
 720     @Override
 721     protected ValueNode createReadHub(StructuredGraph graph, ValueNode object, LoweringTool tool) {
 722         if (tool.getLoweringStage() != LoweringTool.StandardLoweringStage.LOW_TIER) {
 723             return graph.unique(new LoadHubNode(tool.getStampProvider(), object));
 724         }
 725         assert !object.isConstant() || object.isNullConstant();
 726 
 727         KlassPointerStamp hubStamp = KlassPointerStamp.klassNonNull();
 728         if (runtime.getVMConfig().useCompressedClassPointers) {
 729             hubStamp = hubStamp.compressed(runtime.getVMConfig().getKlassEncoding());
 730         }
 731 
 732         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 733         LocationIdentity hubLocation = runtime.getVMConfig().useCompressedClassPointers ? COMPRESSED_HUB_LOCATION : HUB_LOCATION;
 734         FloatingReadNode memoryRead = graph.unique(new FloatingReadNode(address, hubLocation, null, hubStamp, null, BarrierType.NONE));
 735         if (runtime.getVMConfig().useCompressedClassPointers) {
 736             return HotSpotCompressionNode.uncompress(memoryRead, runtime.getVMConfig().getKlassEncoding());
 737         } else {
 738             return memoryRead;
 739         }
 740     }
 741 
 742     private WriteNode createWriteHub(StructuredGraph graph, ValueNode object, ValueNode value) {
 743         assert !object.isConstant() || object.asConstant().isDefaultForKind();
 744 
 745         ValueNode writeValue = value;
 746         if (runtime.getVMConfig().useCompressedClassPointers) {
 747             writeValue = HotSpotCompressionNode.compress(value, runtime.getVMConfig().getKlassEncoding());
 748         }
 749 
 750         AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
 751         return graph.add(new WriteNode(address, HUB_WRITE_LOCATION, writeValue, BarrierType.NONE));
 752     }
 753 
 754     @Override
 755     protected BarrierType fieldLoadBarrierType(ResolvedJavaField f) {
 756         HotSpotResolvedJavaField loadField = (HotSpotResolvedJavaField) f;
 757         BarrierType barrierType = BarrierType.NONE;
 758         if (runtime.getVMConfig().useG1GC && loadField.getJavaKind() == JavaKind.Object && metaAccess.lookupJavaType(Reference.class).equals(loadField.getDeclaringClass()) &&
 759                         loadField.getName().equals("referent")) {
 760             barrierType = BarrierType.PRECISE;
 761         }
 762         return barrierType;
 763     }
 764 
 765     @Override
 766     public int fieldOffset(ResolvedJavaField f) {
 767         HotSpotResolvedJavaField field = (HotSpotResolvedJavaField) f;
 768         return field.offset();
 769     }
 770 
 771     @Override
 772     public int arrayScalingFactor(JavaKind kind) {
 773         if (runtime.getVMConfig().useCompressedOops && kind == JavaKind.Object) {
 774             return super.arrayScalingFactor(JavaKind.Int);
 775         } else {
 776             return super.arrayScalingFactor(kind);
 777         }
 778     }
 779 
 780     @Override
 781     public int arrayBaseOffset(JavaKind kind) {
 782         return getArrayBaseOffset(kind);
 783     }
 784 
 785     @Override
 786     public int arrayLengthOffset() {
 787         return runtime.getVMConfig().arrayOopDescLengthOffset();
 788     }
 789 
 790     @Override
 791     protected final JavaKind getStorageKind(ResolvedJavaField field) {
 792         return field.getJavaKind();
 793     }
 794 }