< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.hotspot/src/org/graalvm/compiler/hotspot/HotSpotCompiledCodeBuilder.java

Print this page




  71 public class HotSpotCompiledCodeBuilder {
  72     public static class Options {
  73         // @formatter:off
  74         @Option(help = "Controls whether the source position information of snippets and method substitutions" +
  75                 " are exposed to HotSpot.  Can be useful when profiling to get more precise position information.")
  76         public static final OptionKey<Boolean> ShowSubstitutionSourceInfo = new OptionKey<>(false);
  77     }
  78 
  79     public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult, OptionValues options) {
  80         String name = compResult.getName();
  81 
  82         byte[] targetCode = compResult.getTargetCode();
  83         int targetCodeSize = compResult.getTargetCodeSize();
  84 
  85         Site[] sites = getSortedSites(compResult, options, codeCache.shouldDebugNonSafepoints() && method != null);
  86 
  87         Assumption[] assumptions = compResult.getAssumptions();
  88 
  89         ResolvedJavaMethod[] methods = compResult.getMethods();
  90 
  91         List<CodeAnnotation> annotations = compResult.getAnnotations();
  92         Comment[] comments = new Comment[annotations.size()];
  93         if (!annotations.isEmpty()) {
  94             for (int i = 0; i < comments.length; i++) {
  95                 CodeAnnotation annotation = annotations.get(i);
  96                 String text;
  97                 if (annotation instanceof CodeComment) {
  98                     CodeComment codeComment = (CodeComment) annotation;
  99                     text = codeComment.value;
 100                 } else if (annotation instanceof JumpTable) {
 101                     JumpTable jumpTable = (JumpTable) annotation;
 102                     text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
 103                 } else {
 104                     text = annotation.toString();
 105                 }
 106                 comments[i] = new Comment(annotation.position, text);
 107             }
 108         }
 109 
 110         DataSection data = compResult.getDataSection();
 111         byte[] dataSection = new byte[data.getSectionSize()];
 112 
 113         ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
 114         List<DataPatch> patches = new ArrayList<>();
 115         data.buildDataSection(buffer, (position, vmConstant) -> {
 116             patches.add(new DataPatch(position, new ConstantReference(vmConstant)));
 117         });
 118 
 119         int dataSectionAlignment = data.getSectionAlignment();
 120         DataPatch[] dataSectionPatches = patches.toArray(new DataPatch[patches.size()]);
 121 
 122         int totalFrameSize = compResult.getTotalFrameSize();
 123         StackSlot customStackArea = compResult.getCustomStackArea();
 124         boolean isImmutablePIC = compResult.isImmutablePIC();
 125 
 126         if (method instanceof HotSpotResolvedJavaMethod) {
 127             HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
 128             int entryBCI = compResult.getEntryBCI();
 129             boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
 130 
 131             int id;
 132             long jvmciEnv;
 133             if (compRequest != null) {
 134                 id = compRequest.getId();
 135                 jvmciEnv = compRequest.getJvmciEnv();
 136             } else {
 137                 id = hsMethod.allocateCompileId(entryBCI);
 138                 jvmciEnv = 0L;
 139             }
 140             return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
 141                             totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciEnv, hasUnsafeAccess);
 142         } else {
 143             return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
 144                             totalFrameSize, customStackArea);
 145         }
 146     }
 147 
 148     static class SiteComparator implements Comparator<Site> {
 149 
 150         /**
 151          * Defines an order for sorting {@link Infopoint}s based on their
 152          * {@linkplain Infopoint#reason reasons}. This is used to choose which infopoint to preserve
 153          * when multiple infopoints collide on the same PC offset. A negative order value implies a
 154          * non-optional infopoint (i.e., must be preserved).
 155          */
 156         static final Map<InfopointReason, Integer> HOTSPOT_INFOPOINT_SORT_ORDER = new EnumMap<>(InfopointReason.class);
 157 
 158         static {
 159             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.SAFEPOINT, -4);
 160             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.CALL, -3);
 161             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.IMPLICIT_EXCEPTION, -2);




  71 public class HotSpotCompiledCodeBuilder {
  72     public static class Options {
  73         // @formatter:off
  74         @Option(help = "Controls whether the source position information of snippets and method substitutions" +
  75                 " are exposed to HotSpot.  Can be useful when profiling to get more precise position information.")
  76         public static final OptionKey<Boolean> ShowSubstitutionSourceInfo = new OptionKey<>(false);
  77     }
  78 
  79     public static HotSpotCompiledCode createCompiledCode(CodeCacheProvider codeCache, ResolvedJavaMethod method, HotSpotCompilationRequest compRequest, CompilationResult compResult, OptionValues options) {
  80         String name = compResult.getName();
  81 
  82         byte[] targetCode = compResult.getTargetCode();
  83         int targetCodeSize = compResult.getTargetCodeSize();
  84 
  85         Site[] sites = getSortedSites(compResult, options, codeCache.shouldDebugNonSafepoints() && method != null);
  86 
  87         Assumption[] assumptions = compResult.getAssumptions();
  88 
  89         ResolvedJavaMethod[] methods = compResult.getMethods();
  90 
  91         List<CodeAnnotation> annotations = compResult.getCodeAnnotations();
  92         Comment[] comments = new Comment[annotations.size()];
  93         if (!annotations.isEmpty()) {
  94             for (int i = 0; i < comments.length; i++) {
  95                 CodeAnnotation annotation = annotations.get(i);
  96                 String text;
  97                 if (annotation instanceof CodeComment) {
  98                     CodeComment codeComment = (CodeComment) annotation;
  99                     text = codeComment.value;
 100                 } else if (annotation instanceof JumpTable) {
 101                     JumpTable jumpTable = (JumpTable) annotation;
 102                     text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]";
 103                 } else {
 104                     text = annotation.toString();
 105                 }
 106                 comments[i] = new Comment(annotation.position, text);
 107             }
 108         }
 109 
 110         DataSection data = compResult.getDataSection();
 111         byte[] dataSection = new byte[data.getSectionSize()];
 112 
 113         ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder());
 114         List<DataPatch> patches = new ArrayList<>();
 115         data.buildDataSection(buffer, (position, vmConstant) -> {
 116             patches.add(new DataPatch(position, new ConstantReference(vmConstant)));
 117         });
 118 
 119         int dataSectionAlignment = data.getSectionAlignment();
 120         DataPatch[] dataSectionPatches = patches.toArray(new DataPatch[patches.size()]);
 121 
 122         int totalFrameSize = compResult.getTotalFrameSize();
 123         StackSlot customStackArea = compResult.getCustomStackArea();
 124         boolean isImmutablePIC = compResult.isImmutablePIC();
 125 
 126         if (method instanceof HotSpotResolvedJavaMethod) {
 127             HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method;
 128             int entryBCI = compResult.getEntryBCI();
 129             boolean hasUnsafeAccess = compResult.hasUnsafeAccess();
 130 
 131             int id;
 132             long jvmciCompileState;
 133             if (compRequest != null) {
 134                 id = compRequest.getId();
 135                 jvmciCompileState = compRequest.getJvmciEnv();
 136             } else {
 137                 id = hsMethod.allocateCompileId(entryBCI);
 138                 jvmciCompileState = 0L;
 139             }
 140             return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
 141                             totalFrameSize, customStackArea, hsMethod, entryBCI, id, jvmciCompileState, hasUnsafeAccess);
 142         } else {
 143             return new HotSpotCompiledCode(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC,
 144                             totalFrameSize, customStackArea);
 145         }
 146     }
 147 
 148     static class SiteComparator implements Comparator<Site> {
 149 
 150         /**
 151          * Defines an order for sorting {@link Infopoint}s based on their
 152          * {@linkplain Infopoint#reason reasons}. This is used to choose which infopoint to preserve
 153          * when multiple infopoints collide on the same PC offset. A negative order value implies a
 154          * non-optional infopoint (i.e., must be preserved).
 155          */
 156         static final Map<InfopointReason, Integer> HOTSPOT_INFOPOINT_SORT_ORDER = new EnumMap<>(InfopointReason.class);
 157 
 158         static {
 159             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.SAFEPOINT, -4);
 160             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.CALL, -3);
 161             HOTSPOT_INFOPOINT_SORT_ORDER.put(InfopointReason.IMPLICIT_EXCEPTION, -2);


< prev index next >