src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataPatchProcessor.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File hotspot Sdiff src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc

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

Print this page


   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 
  24 package jdk.tools.jaotc;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.BinaryContainer;
  30 import jdk.tools.jaotc.binformat.Relocation;
  31 import jdk.tools.jaotc.binformat.Relocation.RelocType;
  32 import jdk.tools.jaotc.binformat.Symbol;
  33 import jdk.tools.jaotc.binformat.Symbol.Binding;
  34 import jdk.tools.jaotc.binformat.Symbol.Kind;
  35 import jdk.tools.jaotc.AOTCompiledClass.AOTKlassData;
  36 import org.graalvm.compiler.code.DataSection;
  37 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
  38 
  39 import jdk.vm.ci.code.TargetDescription;
  40 import jdk.vm.ci.code.site.ConstantReference;
  41 import jdk.vm.ci.code.site.DataPatch;
  42 import jdk.vm.ci.code.site.DataSectionReference;
  43 import jdk.vm.ci.code.site.Reference;
  44 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
  45 import jdk.vm.ci.hotspot.HotSpotObjectConstant;
  46 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  47 import jdk.vm.ci.hotspot.HotSpotSentinelConstant;
  48 import jdk.vm.ci.meta.VMConstant;
  49 
  50 class DataPatchProcessor {
  51 
  52     private final TargetDescription target;
  53 
  54     private final BinaryContainer binaryContainer;
  55 
  56     DataPatchProcessor(DataBuilder dataBuilder) {
  57         this.target = dataBuilder.getBackend().getTarget();
  58         this.binaryContainer = dataBuilder.getBinaryContainer();
  59     }
  60 
  61     /**
  62      * Process a {@link DataPatch} generated by the compiler and create all needed binary section
  63      * constructs.
  64      */
  65     void process(CompiledMethodInfo methodInfo, DataPatch dataPatch) {
  66         Reference reference = dataPatch.reference;
  67         if (reference instanceof ConstantReference) {
  68             processConstantReference(dataPatch, methodInfo);
  69         } else if (reference instanceof DataSectionReference) {
  70             processDataSectionReference(dataPatch, methodInfo);


  72             throw new InternalError("Unknown data patch reference: " + reference);
  73         }
  74     }
  75 
  76     private void processConstantReference(DataPatch dataPatch, CompiledMethodInfo methodInfo) {
  77         HotSpotConstantLoadAction action = (HotSpotConstantLoadAction) dataPatch.note;
  78         ConstantReference constantReference = (ConstantReference) dataPatch.reference;
  79         assert action != null : "action should be set";
  80 
  81         VMConstant constant = constantReference.getConstant();
  82         String targetSymbol = null;
  83         String gotName = null;
  84         if (constant instanceof HotSpotMetaspaceConstant) {
  85             HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant;
  86             if (metaspaceConstant.asResolvedJavaType() != null) {
  87                 HotSpotResolvedObjectType type = metaspaceConstant.asResolvedJavaType();
  88                 targetSymbol = type.getName();
  89                 gotName = ((action == HotSpotConstantLoadAction.INITIALIZE) ? "got.init." : "got.") + targetSymbol;
  90                 methodInfo.addDependentKlassData(binaryContainer, type);
  91             } else if (metaspaceConstant.asResolvedJavaMethod() != null && action == HotSpotConstantLoadAction.LOAD_COUNTERS) {
  92                 targetSymbol = "counters." + MiscUtils.uniqueMethodName(metaspaceConstant.asResolvedJavaMethod());
  93                 gotName = "got." + targetSymbol;
  94                 binaryContainer.addMetaspaceSymbol(targetSymbol);
  95             }
  96         } else if (constant instanceof HotSpotObjectConstant) {
  97             // String constant.
  98             HotSpotObjectConstant oopConstant = (HotSpotObjectConstant) constant;
  99             targetSymbol = "ldc." + oopConstant.toValueString();
 100             Integer offset = binaryContainer.addOopSymbol(targetSymbol);
 101             gotName = "got.ldc." + offset;
 102         } else if (constant instanceof HotSpotSentinelConstant) {
 103             targetSymbol = "state.M" + methodInfo.getCodeId();
 104             gotName = "got." + targetSymbol;
 105         }
 106 
 107         assert gotName != null : "Unknown constant type: " + constant;
 108 
 109         InstructionDecoder decoder = InstructionDecoder.getInstructionDecoder(target);
 110         decoder.decodePosition(methodInfo.getCompilationResult().getTargetCode(), dataPatch.pcOffset);
 111         int instructionEndOffset = decoder.currentEndOfInstruction();
 112 
 113         int textBaseOffset = methodInfo.getTextSectionOffset();
 114         int relocOffset = textBaseOffset + instructionEndOffset;


   1 /*
   2  * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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 
  24 package jdk.tools.jaotc;
  25 
  26 import java.nio.ByteBuffer;
  27 import java.nio.ByteOrder;
  28 
  29 import jdk.tools.jaotc.binformat.BinaryContainer;
  30 import jdk.tools.jaotc.binformat.Relocation;
  31 import jdk.tools.jaotc.binformat.Relocation.RelocType;
  32 import jdk.tools.jaotc.binformat.Symbol;
  33 import jdk.tools.jaotc.binformat.Symbol.Binding;
  34 import jdk.tools.jaotc.binformat.Symbol.Kind;

  35 import org.graalvm.compiler.code.DataSection;
  36 import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
  37 
  38 import jdk.vm.ci.code.TargetDescription;
  39 import jdk.vm.ci.code.site.ConstantReference;
  40 import jdk.vm.ci.code.site.DataPatch;
  41 import jdk.vm.ci.code.site.DataSectionReference;
  42 import jdk.vm.ci.code.site.Reference;
  43 import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant;
  44 import jdk.vm.ci.hotspot.HotSpotObjectConstant;
  45 import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
  46 import jdk.vm.ci.hotspot.HotSpotSentinelConstant;
  47 import jdk.vm.ci.meta.VMConstant;
  48 
  49 final class DataPatchProcessor {
  50 
  51     private final TargetDescription target;
  52 
  53     private final BinaryContainer binaryContainer;
  54 
  55     DataPatchProcessor(DataBuilder dataBuilder) {
  56         this.target = dataBuilder.getBackend().getTarget();
  57         this.binaryContainer = dataBuilder.getBinaryContainer();
  58     }
  59 
  60     /**
  61      * Process a {@link DataPatch} generated by the compiler and create all needed binary section
  62      * constructs.
  63      */
  64     void process(CompiledMethodInfo methodInfo, DataPatch dataPatch) {
  65         Reference reference = dataPatch.reference;
  66         if (reference instanceof ConstantReference) {
  67             processConstantReference(dataPatch, methodInfo);
  68         } else if (reference instanceof DataSectionReference) {
  69             processDataSectionReference(dataPatch, methodInfo);


  71             throw new InternalError("Unknown data patch reference: " + reference);
  72         }
  73     }
  74 
  75     private void processConstantReference(DataPatch dataPatch, CompiledMethodInfo methodInfo) {
  76         HotSpotConstantLoadAction action = (HotSpotConstantLoadAction) dataPatch.note;
  77         ConstantReference constantReference = (ConstantReference) dataPatch.reference;
  78         assert action != null : "action should be set";
  79 
  80         VMConstant constant = constantReference.getConstant();
  81         String targetSymbol = null;
  82         String gotName = null;
  83         if (constant instanceof HotSpotMetaspaceConstant) {
  84             HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant;
  85             if (metaspaceConstant.asResolvedJavaType() != null) {
  86                 HotSpotResolvedObjectType type = metaspaceConstant.asResolvedJavaType();
  87                 targetSymbol = type.getName();
  88                 gotName = ((action == HotSpotConstantLoadAction.INITIALIZE) ? "got.init." : "got.") + targetSymbol;
  89                 methodInfo.addDependentKlassData(binaryContainer, type);
  90             } else if (metaspaceConstant.asResolvedJavaMethod() != null && action == HotSpotConstantLoadAction.LOAD_COUNTERS) {
  91                 targetSymbol = "counters." + JavaMethodInfo.uniqueMethodName(metaspaceConstant.asResolvedJavaMethod());
  92                 gotName = "got." + targetSymbol;
  93                 binaryContainer.addCountersSymbol(targetSymbol);
  94             }
  95         } else if (constant instanceof HotSpotObjectConstant) {
  96             // String constant.
  97             HotSpotObjectConstant oopConstant = (HotSpotObjectConstant) constant;
  98             targetSymbol = "ldc." + oopConstant.toValueString();
  99             Integer offset = binaryContainer.addOopSymbol(targetSymbol);
 100             gotName = "got.ldc." + offset;
 101         } else if (constant instanceof HotSpotSentinelConstant) {
 102             targetSymbol = "state.M" + methodInfo.getCodeId();
 103             gotName = "got." + targetSymbol;
 104         }
 105 
 106         assert gotName != null : "Unknown constant type: " + constant;
 107 
 108         InstructionDecoder decoder = InstructionDecoder.getInstructionDecoder(target);
 109         decoder.decodePosition(methodInfo.getCompilationResult().getTargetCode(), dataPatch.pcOffset);
 110         int instructionEndOffset = decoder.currentEndOfInstruction();
 111 
 112         int textBaseOffset = methodInfo.getTextSectionOffset();
 113         int relocOffset = textBaseOffset + instructionEndOffset;


src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/DataPatchProcessor.java
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File