< prev index next >

src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/CodeSectionProcessor.java

Print this page




  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 
  24 package jdk.tools.jaotc;
  25 
  26 import java.util.ArrayList;
  27 
  28 import jdk.tools.jaotc.binformat.BinaryContainer;
  29 import jdk.tools.jaotc.binformat.CodeContainer;
  30 import jdk.tools.jaotc.binformat.Symbol;
  31 import jdk.tools.jaotc.StubInformation;
  32 import org.graalvm.compiler.code.CompilationResult;
  33 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
  34 


  35 import jdk.vm.ci.code.TargetDescription;
  36 import jdk.vm.ci.code.site.Call;
  37 import jdk.vm.ci.code.site.Infopoint;
  38 import jdk.vm.ci.code.site.InfopointReason;
  39 import jdk.vm.ci.meta.ResolvedJavaMethod;
  40 
  41 final class CodeSectionProcessor {
  42 
  43     private final TargetDescription target;
  44 
  45     private final BinaryContainer binaryContainer;
  46 
  47     CodeSectionProcessor(DataBuilder dataBuilder) {
  48         this.target = dataBuilder.getBackend().getTarget();
  49         this.binaryContainer = dataBuilder.getBinaryContainer();
  50     }
  51 
  52     /**
  53      * Method that looks at code section of a compiled result {@code compClass} and records function
  54      * entry point symbols along with the text section contents. Note that the text section contents
  55      * are not yet ready to be written in the form of a binary text section since the contents may
  56      * need to be patched with references to other sections.
  57      *
  58      * @param compClass Graal compilation result.
  59      */
  60     void process(AOTCompiledClass compClass) {
  61         ArrayList<CompiledMethodInfo> compiledMethods = compClass.getCompiledMethods();
  62 
  63         for (CompiledMethodInfo methodInfo : compiledMethods) {
  64             CompilationResult compResult = methodInfo.getCompilationResult();
  65 
  66             byte[] targetCode = compResult.getTargetCode();
  67             int targetCodeSize = compResult.getTargetCodeSize();
  68             JavaMethodInfo compMethod = methodInfo.getMethodInfo();
  69 
  70             // Step through all foreign calls, for every call, clear destination.
  71             // Otherwise libelf may not patch them correctly.
  72             for (Infopoint infopoint : compResult.getInfopoints()) {
  73                 if (infopoint.reason == InfopointReason.CALL) {
  74                     final Call callInfopoint = (Call) infopoint;
  75                     if (callInfopoint.target instanceof HotSpotForeignCallLinkage) {

  76                         // TODO 4 is x86 size of relative displacement.
  77                         // For SPARC need something different.
  78                         int destOffset = infopoint.pcOffset + callInfopoint.size - 4;
  79                         targetCode[destOffset + 0] = 0;
  80                         targetCode[destOffset + 1] = 0;
  81                         targetCode[destOffset + 2] = 0;
  82                         targetCode[destOffset + 3] = 0;
  83                     }
  84                 }
  85             }
  86 
  87             String entry = compMethod.getSymbolName();
  88             assert entry != null : "missing name for compiled method";
  89 
  90             // Align and pad method entry
  91             CodeContainer codeSection = binaryContainer.getCodeContainer();
  92             int codeIdOffset = BinaryContainer.alignUp(codeSection, binaryContainer.getCodeSegmentSize());
  93             // Store CodeId into code. It will be use by find_aot() using code.segments
  94             methodInfo.setCodeId();
  95             binaryContainer.appendIntToCode(methodInfo.getCodeId());




  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 
  24 package jdk.tools.jaotc;
  25 
  26 import java.util.ArrayList;
  27 
  28 import jdk.tools.jaotc.binformat.BinaryContainer;
  29 import jdk.tools.jaotc.binformat.CodeContainer;
  30 import jdk.tools.jaotc.binformat.Symbol;
  31 import jdk.tools.jaotc.StubInformation;
  32 import org.graalvm.compiler.code.CompilationResult;
  33 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
  34 
  35 import jdk.vm.ci.aarch64.AArch64;
  36 import jdk.vm.ci.amd64.AMD64;
  37 import jdk.vm.ci.code.TargetDescription;
  38 import jdk.vm.ci.code.site.Call;
  39 import jdk.vm.ci.code.site.Infopoint;
  40 import jdk.vm.ci.code.site.InfopointReason;
  41 import jdk.vm.ci.meta.ResolvedJavaMethod;
  42 
  43 final class CodeSectionProcessor {
  44 
  45     private final TargetDescription target;
  46 
  47     private final BinaryContainer binaryContainer;
  48 
  49     CodeSectionProcessor(DataBuilder dataBuilder) {
  50         this.target = dataBuilder.getBackend().getTarget();
  51         this.binaryContainer = dataBuilder.getBinaryContainer();
  52     }
  53 
  54     /**
  55      * Method that looks at code section of a compiled result {@code compClass} and records function
  56      * entry point symbols along with the text section contents. Note that the text section contents
  57      * are not yet ready to be written in the form of a binary text section since the contents may
  58      * need to be patched with references to other sections.
  59      *
  60      * @param compClass Graal compilation result.
  61      */
  62     void process(AOTCompiledClass compClass) {
  63         ArrayList<CompiledMethodInfo> compiledMethods = compClass.getCompiledMethods();
  64 
  65         for (CompiledMethodInfo methodInfo : compiledMethods) {
  66             CompilationResult compResult = methodInfo.getCompilationResult();
  67 
  68             byte[] targetCode = compResult.getTargetCode();
  69             int targetCodeSize = compResult.getTargetCodeSize();
  70             JavaMethodInfo compMethod = methodInfo.getMethodInfo();
  71 
  72             // Step through all foreign calls, for every call, clear destination.
  73             // Otherwise libelf may not patch them correctly.
  74             for (Infopoint infopoint : compResult.getInfopoints()) {
  75                 if (infopoint.reason == InfopointReason.CALL) {
  76                     final Call callInfopoint = (Call) infopoint;
  77                     if (callInfopoint.target instanceof HotSpotForeignCallLinkage &&
  78                         target.arch instanceof AMD64) {
  79                         // TODO 4 is x86 size of relative displacement.
  80                         // For SPARC need something different.
  81                         int destOffset = infopoint.pcOffset + callInfopoint.size - 4;
  82                         targetCode[destOffset + 0] = 0;
  83                         targetCode[destOffset + 1] = 0;
  84                         targetCode[destOffset + 2] = 0;
  85                         targetCode[destOffset + 3] = 0;
  86                     }
  87                 }
  88             }
  89 
  90             String entry = compMethod.getSymbolName();
  91             assert entry != null : "missing name for compiled method";
  92 
  93             // Align and pad method entry
  94             CodeContainer codeSection = binaryContainer.getCodeContainer();
  95             int codeIdOffset = BinaryContainer.alignUp(codeSection, binaryContainer.getCodeSegmentSize());
  96             // Store CodeId into code. It will be use by find_aot() using code.segments
  97             methodInfo.setCodeId();
  98             binaryContainer.appendIntToCode(methodInfo.getCodeId());


< prev index next >