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 jdk.vm.ci.hotspot; 24 25 import java.nio.*; 26 import java.util.*; 27 import java.util.stream.*; 28 import java.util.stream.Stream.Builder; 29 30 import jdk.vm.ci.code.*; 31 import jdk.vm.ci.code.CompilationResult.CodeAnnotation; 32 import jdk.vm.ci.code.CompilationResult.CodeComment; 33 import jdk.vm.ci.code.CompilationResult.DataPatch; 34 import jdk.vm.ci.code.CompilationResult.ExceptionHandler; 35 import jdk.vm.ci.code.CompilationResult.Infopoint; 36 import jdk.vm.ci.code.CompilationResult.JumpTable; 37 import jdk.vm.ci.code.CompilationResult.Mark; 38 import jdk.vm.ci.code.CompilationResult.Site; 39 import jdk.vm.ci.meta.*; 40 import jdk.vm.ci.meta.Assumptions.Assumption; 41 42 /** 43 * A {@link CompilationResult} with additional HotSpot-specific information required for installing 44 * the code in HotSpot's code cache. 45 */ 46 public abstract class HotSpotCompiledCode { 47 48 public final String name; 49 public final Site[] sites; 50 public final ExceptionHandler[] exceptionHandlers; 51 public final Comment[] comments; 52 public final Assumption[] assumptions; 53 54 public final byte[] targetCode; 55 public final int targetCodeSize; 56 57 public final byte[] dataSection; 58 public final int dataSectionAlignment; 59 public final DataPatch[] dataSectionPatches; 60 public final boolean isImmutablePIC; 61 62 public final int totalFrameSize; 63 public final int customStackAreaOffset; 64 65 /** 66 * The list of the methods whose bytecodes were used as input to the compilation. If 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 assumptions = compResult.getAssumptions(); 110 assert validateFrames(); 111 112 targetCode = compResult.getTargetCode(); 113 targetCodeSize = compResult.getTargetCodeSize(); 114 115 DataSection data = compResult.getDataSection(); 116 if (!data.isFinalized()) { 117 data.finalizeLayout(); 118 } 119 dataSection = new byte[data.getSectionSize()]; 120 121 ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder()); 122 Builder<DataPatch> patchBuilder = Stream.builder(); 123 data.buildDataSection(buffer, patchBuilder); 124 125 dataSectionAlignment = data.getSectionAlignment(); 126 dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]); 127 128 isImmutablePIC = compResult.isImmutablePIC(); 129 130 totalFrameSize = compResult.getTotalFrameSize(); 131 customStackAreaOffset = compResult.getCustomStackAreaOffset(); 132 133 methods = compResult.getMethods(); 134 } 135 136 /** 137 * Ensure that all the frames passed into HotSpot are properly formatted with an empty or 138 * illegal slot following double word slots. 159 return s1.pcOffset - s2.pcOffset; 160 } 161 } 162 163 private static Site[] getSortedSites(CompilationResult target) { 164 List<?>[] lists = new List<?>[]{target.getInfopoints(), target.getDataPatches(), target.getMarks()}; 165 int count = 0; 166 for (List<?> list : lists) { 167 count += list.size(); 168 } 169 Site[] result = new Site[count]; 170 int pos = 0; 171 for (List<?> list : lists) { 172 for (Object elem : list) { 173 result[pos++] = (Site) elem; 174 } 175 } 176 Arrays.sort(result, new SiteComparator()); 177 return result; 178 } 179 } | 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 jdk.vm.ci.hotspot; 24 25 import java.nio.ByteBuffer; 26 import java.nio.ByteOrder; 27 import java.util.Arrays; 28 import java.util.Comparator; 29 import java.util.List; 30 import java.util.stream.Stream; 31 import java.util.stream.Stream.Builder; 32 33 import jdk.vm.ci.code.BytecodeFrame; 34 import jdk.vm.ci.code.CompilationResult; 35 import jdk.vm.ci.code.CompilationResult.CodeAnnotation; 36 import jdk.vm.ci.code.CompilationResult.CodeComment; 37 import jdk.vm.ci.code.CompilationResult.DataPatch; 38 import jdk.vm.ci.code.CompilationResult.ExceptionHandler; 39 import jdk.vm.ci.code.CompilationResult.Infopoint; 40 import jdk.vm.ci.code.CompilationResult.JumpTable; 41 import jdk.vm.ci.code.CompilationResult.Mark; 42 import jdk.vm.ci.code.CompilationResult.Site; 43 import jdk.vm.ci.code.DataSection; 44 import jdk.vm.ci.meta.Assumptions.Assumption; 45 import jdk.vm.ci.meta.ResolvedJavaMethod; 46 47 /** 48 * A {@link CompilationResult} with additional HotSpot-specific information required for installing 49 * the code in HotSpot's code cache. 50 */ 51 public class HotSpotCompiledCode { 52 53 public final String name; 54 public final Site[] sites; 55 public final ExceptionHandler[] exceptionHandlers; 56 public final Comment[] comments; 57 public final Assumption[] assumptions; 58 59 public final byte[] targetCode; 60 public final int targetCodeSize; 61 62 public final byte[] dataSection; 63 public final int dataSectionAlignment; 64 public final DataPatch[] dataSectionPatches; 65 public final boolean isImmutablePIC; 66 67 public final int totalFrameSize; 68 public final int customStackAreaOffset; 69 70 /** 71 * The list of the methods whose bytecodes were used as input to the compilation. If 101 String text; 102 if (annotation instanceof CodeComment) { 103 CodeComment codeComment = (CodeComment) annotation; 104 text = codeComment.value; 105 } else if (annotation instanceof JumpTable) { 106 JumpTable jumpTable = (JumpTable) annotation; 107 text = "JumpTable [" + jumpTable.low + " .. " + jumpTable.high + "]"; 108 } else { 109 text = annotation.toString(); 110 } 111 comments[i] = new Comment(annotation.position, text); 112 } 113 } 114 assumptions = compResult.getAssumptions(); 115 assert validateFrames(); 116 117 targetCode = compResult.getTargetCode(); 118 targetCodeSize = compResult.getTargetCodeSize(); 119 120 DataSection data = compResult.getDataSection(); 121 data.finalizeLayout(); 122 dataSection = new byte[data.getSectionSize()]; 123 124 ByteBuffer buffer = ByteBuffer.wrap(dataSection).order(ByteOrder.nativeOrder()); 125 Builder<DataPatch> patchBuilder = Stream.builder(); 126 data.buildDataSection(buffer, patchBuilder); 127 128 dataSectionAlignment = data.getSectionAlignment(); 129 dataSectionPatches = patchBuilder.build().toArray(len -> new DataPatch[len]); 130 131 isImmutablePIC = compResult.isImmutablePIC(); 132 133 totalFrameSize = compResult.getTotalFrameSize(); 134 customStackAreaOffset = compResult.getCustomStackAreaOffset(); 135 136 methods = compResult.getMethods(); 137 } 138 139 /** 140 * Ensure that all the frames passed into HotSpot are properly formatted with an empty or 141 * illegal slot following double word slots. 162 return s1.pcOffset - s2.pcOffset; 163 } 164 } 165 166 private static Site[] getSortedSites(CompilationResult target) { 167 List<?>[] lists = new List<?>[]{target.getInfopoints(), target.getDataPatches(), target.getMarks()}; 168 int count = 0; 169 for (List<?> list : lists) { 170 count += list.size(); 171 } 172 Site[] result = new Site[count]; 173 int pos = 0; 174 for (List<?> list : lists) { 175 for (Object elem : list) { 176 result[pos++] = (Site) elem; 177 } 178 } 179 Arrays.sort(result, new SiteComparator()); 180 return result; 181 } 182 183 @Override 184 public String toString() { 185 return name; 186 } 187 } |