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; 26 27 import static org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder.Options.ShowSubstitutionSourceInfo; 28 import static org.graalvm.util.CollectionsUtil.anyMatch; 29 30 import java.nio.ByteBuffer; 31 import java.nio.ByteOrder; 32 import java.util.ArrayList; 33 import java.util.Collections; 34 import java.util.Comparator; 35 import java.util.EnumMap; 36 import java.util.List; 37 import java.util.ListIterator; 38 import java.util.Map; 39 import java.util.stream.Stream; 40 import java.util.stream.Stream.Builder; 41 42 import org.graalvm.compiler.api.replacements.MethodSubstitution; 43 import org.graalvm.compiler.api.replacements.Snippet; 44 import org.graalvm.compiler.code.CompilationResult; 45 import org.graalvm.compiler.code.CompilationResult.CodeAnnotation; 46 import org.graalvm.compiler.code.CompilationResult.CodeComment; 47 import org.graalvm.compiler.code.CompilationResult.JumpTable; 48 import org.graalvm.compiler.code.DataSection; 49 import org.graalvm.compiler.code.SourceMapping; 50 import org.graalvm.compiler.debug.GraalError; 51 import org.graalvm.compiler.graph.NodeSourcePosition; 52 import org.graalvm.compiler.options.Option; 53 import org.graalvm.compiler.options.OptionKey; 54 import org.graalvm.compiler.options.OptionValues; 55 56 import jdk.vm.ci.code.CodeCacheProvider; 57 import jdk.vm.ci.code.DebugInfo; 58 import jdk.vm.ci.code.StackSlot; 59 import jdk.vm.ci.code.site.ConstantReference; 60 import jdk.vm.ci.code.site.DataPatch; 96 for (int i = 0; i < comments.length; i++) { 97 CodeAnnotation annotation = annotations.get(i); 98 String text; 99 if (annotation instanceof CodeComment) { 100 CodeComment codeComment = (CodeComment) annotation; 101 text = codeComment.value; 102 } else if (annotation instanceof JumpTable) { 103 JumpTable jumpTable = (JumpTable) annotation; 104 text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]"; 105 } else { 106 text = annotation.toString(); 107 } 108 comments[i] = new Comment(annotation.position, text); 109 } 110 } 111 112 DataSection data = compResult.getDataSection(); 113 byte[] dataSection = new byte[data.getSectionSize()]; 114 115 ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder()); 116 Builder<DataPatch> patchBuilder = Stream.builder(); 117 data.buildDataSection(buffer, (position, vmConstant) -> { 118 patchBuilder.accept(new DataPatch(position, new ConstantReference(vmConstant))); 119 }); 120 121 int dataSectionAlignment = data.getSectionAlignment(); 122 DataPatch[] dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]); 123 124 int totalFrameSize = compResult.getTotalFrameSize(); 125 StackSlot customStackArea = compResult.getCustomStackArea(); 126 boolean isImmutablePIC = compResult.isImmutablePIC(); 127 128 if (method instanceof HotSpotResolvedJavaMethod) { 129 HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) method; 130 int entryBCI = compResult.getEntryBCI(); 131 boolean hasUnsafeAccess = compResult.hasUnsafeAccess(); 132 133 int id; 134 long jvmciEnv; 135 if (compRequest != null) { 136 id = compRequest.getId(); 137 jvmciEnv = compRequest.getJvmciEnv(); 138 } else { 139 id = hsMethod.allocateCompileId(entryBCI); 140 jvmciEnv = 0L; 141 } 142 return new HotSpotCompiledNmethod(name, targetCode, targetCodeSize, sites, assumptions, methods, comments, dataSection, dataSectionAlignment, dataSectionPatches, isImmutablePIC, | 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; 26 27 import static org.graalvm.compiler.hotspot.HotSpotCompiledCodeBuilder.Options.ShowSubstitutionSourceInfo; 28 import static org.graalvm.util.CollectionsUtil.anyMatch; 29 30 import java.nio.ByteBuffer; 31 import java.nio.ByteOrder; 32 import java.util.ArrayList; 33 import java.util.Collections; 34 import java.util.Comparator; 35 import java.util.EnumMap; 36 import java.util.List; 37 import java.util.ListIterator; 38 import java.util.Map; 39 40 import org.graalvm.compiler.api.replacements.MethodSubstitution; 41 import org.graalvm.compiler.api.replacements.Snippet; 42 import org.graalvm.compiler.code.CompilationResult; 43 import org.graalvm.compiler.code.CompilationResult.CodeAnnotation; 44 import org.graalvm.compiler.code.CompilationResult.CodeComment; 45 import org.graalvm.compiler.code.CompilationResult.JumpTable; 46 import org.graalvm.compiler.code.DataSection; 47 import org.graalvm.compiler.code.SourceMapping; 48 import org.graalvm.compiler.debug.GraalError; 49 import org.graalvm.compiler.graph.NodeSourcePosition; 50 import org.graalvm.compiler.options.Option; 51 import org.graalvm.compiler.options.OptionKey; 52 import org.graalvm.compiler.options.OptionValues; 53 54 import jdk.vm.ci.code.CodeCacheProvider; 55 import jdk.vm.ci.code.DebugInfo; 56 import jdk.vm.ci.code.StackSlot; 57 import jdk.vm.ci.code.site.ConstantReference; 58 import jdk.vm.ci.code.site.DataPatch; 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, |