gt:         int position = asm.position();
context: /*
   * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.
   *
   * This code is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   * version 2 for more details (a copy is included in the LICENSE file that
   * accompanied this code).
   *
   * You should have received a copy of the GNU General Public License version
   * 2 along with this work; if not, write to the Free Software Foundation,
   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   *
   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  package com.oracle.graal.lir.asm;
  
  import static com.oracle.graal.lir.LIRValueUtil.asJavaConstant;
  import static com.oracle.graal.lir.LIRValueUtil.isJavaConstant;
  import static jdk.vm.ci.code.ValueUtil.asStackSlot;
  import static jdk.vm.ci.code.ValueUtil.isStackSlot;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.IdentityHashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.function.Consumer;
  
  import com.oracle.graal.asm.AbstractAddress;
  import com.oracle.graal.asm.Assembler;
  import com.oracle.graal.asm.NumUtil;
  import com.oracle.graal.code.CompilationResult;
  import com.oracle.graal.code.CompilationResult.CodeAnnotation;
  import com.oracle.graal.code.DataSection.Data;
  import com.oracle.graal.code.DataSection.RawData;
  import com.oracle.graal.compiler.common.cfg.AbstractBlockBase;
  import com.oracle.graal.compiler.common.spi.ForeignCallsProvider;
  import com.oracle.graal.compiler.common.type.DataPointerConstant;
  import com.oracle.graal.debug.Debug;
  import com.oracle.graal.debug.GraalError;
  import com.oracle.graal.graph.NodeSourcePosition;
  import com.oracle.graal.lir.LIR;
  import com.oracle.graal.lir.LIRFrameState;
  import com.oracle.graal.lir.LIRInstruction;
  import com.oracle.graal.lir.LabelRef;
  import com.oracle.graal.lir.framemap.FrameMap;
  import com.oracle.graal.options.Option;
  import com.oracle.graal.options.OptionType;
  import com.oracle.graal.options.OptionValue;
  
  import jdk.vm.ci.code.CodeCacheProvider;
  import jdk.vm.ci.code.DebugInfo;
  import jdk.vm.ci.code.StackSlot;
  import jdk.vm.ci.code.TargetDescription;
  import jdk.vm.ci.code.site.ConstantReference;
  import jdk.vm.ci.code.site.DataSectionReference;
  import jdk.vm.ci.code.site.InfopointReason;
  import jdk.vm.ci.code.site.Mark;
  import jdk.vm.ci.meta.Constant;
  import jdk.vm.ci.meta.InvokeTarget;
  import jdk.vm.ci.meta.JavaConstant;
  import jdk.vm.ci.meta.JavaKind;
  import jdk.vm.ci.meta.VMConstant;
  import jdk.vm.ci.meta.Value;
  
  /**
   * Fills in a {@link CompilationResult} as its code is being assembled.
   *
   * @see CompilationResultBuilderFactory
   */
  public class CompilationResultBuilder {
  
      // @formatter:off
      @Option(help = "Include the LIR as comments with the final assembly.", type = OptionType.Debug)
      public static final OptionValue<Boolean> PrintLIRWithAssembly = new OptionValue<>(false);
      // @formatter:on
  
      private static class ExceptionInfo {
  
          public final int codeOffset;
          public final LabelRef exceptionEdge;
  
          ExceptionInfo(int pcOffset, LabelRef exceptionEdge) {
              this.codeOffset = pcOffset;
              this.exceptionEdge = exceptionEdge;
          }
      }
  
      /**
       * Wrapper for a code annotation that was produced by the {@link Assembler}.
       */
      public static final class AssemblerAnnotation extends CodeAnnotation {
  
          public final Assembler.CodeAnnotation assemblerCodeAnnotation;
  
          public AssemblerAnnotation(Assembler.CodeAnnotation assemblerCodeAnnotation) {
              super(assemblerCodeAnnotation.instructionPosition);
              this.assemblerCodeAnnotation = assemblerCodeAnnotation;
          }
  
          @Override
          public boolean equals(Object obj) {
              return this == obj;
          }
  
          @Override
          public String toString() {
              return assemblerCodeAnnotation.toString();
          }
      }
  
      public final Assembler asm;
      public final DataBuilder dataBuilder;
      public final CompilationResult compilationResult;
      public final TargetDescription target;
      public final CodeCacheProvider codeCache;
      public final ForeignCallsProvider foreignCalls;
      public final FrameMap frameMap;
  
      /**
       * The LIR for which code is being generated.
       */
      private LIR lir;
  
      /**
       * The index of the block currently being emitted.
       */
      private int currentBlockIndex;
  
      /**
       * The object that emits code for managing a method's frame.
       */
      public final FrameContext frameContext;
  
      private List<ExceptionInfo> exceptionInfoList;
  
      private final Map<Constant, Data> dataCache;
  
      private Consumer<LIRInstruction> beforeOp;
      private Consumer<LIRInstruction> afterOp;
  
      public CompilationResultBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, DataBuilder dataBuilder, FrameContext frameContext,
                      CompilationResult compilationResult) {
          // constants are already GVNed in the high level graph, so we can use an IdentityHashMap
          this(codeCache, foreignCalls, frameMap, asm, dataBuilder, frameContext, compilationResult, new IdentityHashMap<>());
      }
  
      public CompilationResultBuilder(CodeCacheProvider codeCache, ForeignCallsProvider foreignCalls, FrameMap frameMap, Assembler asm, DataBuilder dataBuilder, FrameContext frameContext,
                      CompilationResult compilationResult, Map<Constant, Data> dataCache) {
          this.target = codeCache.getTarget();
          this.codeCache = codeCache;
          this.foreignCalls = foreignCalls;
          this.frameMap = frameMap;
          this.asm = asm;
          this.dataBuilder = dataBuilder;
          this.compilationResult = compilationResult;
          this.frameContext = frameContext;
          assert frameContext != null;
          this.dataCache = dataCache;
  
          boolean assertionsEnabled = false;
          assert (assertionsEnabled = true) == true;
          if (dataBuilder.needDetailedPatchingInformation() || assertionsEnabled) {
              /*
               * Always enabled in debug mode, even when the VM does not request detailed information,
               * to increase test coverage.
               */
              asm.setCodePatchingAnnotationConsumer(assemblerCodeAnnotation -> compilationResult.addAnnotation(new AssemblerAnnotation(assemblerCodeAnnotation)));
          }
      }
  
      public void setTotalFrameSize(int frameSize) {
          compilationResult.setTotalFrameSize(frameSize);
      }
  
      public void setMaxInterpreterFrameSize(int maxInterpreterFrameSize) {
          compilationResult.setMaxInterpreterFrameSize(maxInterpreterFrameSize);
      }
  
      public Mark recordMark(Object id) {
          return compilationResult.recordMark(asm.position(), id);
      }
  
      public void blockComment(String s) {
          compilationResult.addAnnotation(new CompilationResult.CodeComment(asm.position(), s));
      }
  
      /**
       * Sets the {@linkplain CompilationResult#setTargetCode(byte[], int) code} and
       * {@linkplain CompilationResult#recordExceptionHandler(int, int) exception handler} fields of
       * the compilation result and then {@linkplain #closeCompilationResult() closes} it.
       */
      public void finish() {
  