< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.code/src/org/graalvm/compiler/code/CompilationResult.java

Print this page




  38 import jdk.internal.vm.compiler.collections.EconomicSet;
  39 import org.graalvm.compiler.core.common.CompilationIdentifier;
  40 import org.graalvm.compiler.graph.NodeSourcePosition;
  41 
  42 import jdk.vm.ci.code.DebugInfo;
  43 import jdk.vm.ci.code.StackSlot;
  44 import jdk.vm.ci.code.site.Call;
  45 import jdk.vm.ci.code.site.ConstantReference;
  46 import jdk.vm.ci.code.site.DataPatch;
  47 import jdk.vm.ci.code.site.DataSectionReference;
  48 import jdk.vm.ci.code.site.ExceptionHandler;
  49 import jdk.vm.ci.code.site.Infopoint;
  50 import jdk.vm.ci.code.site.InfopointReason;
  51 import jdk.vm.ci.code.site.Mark;
  52 import jdk.vm.ci.code.site.Reference;
  53 import jdk.vm.ci.code.site.Site;
  54 import jdk.vm.ci.meta.Assumptions.Assumption;
  55 import jdk.vm.ci.meta.InvokeTarget;
  56 import jdk.vm.ci.meta.ResolvedJavaField;
  57 import jdk.vm.ci.meta.ResolvedJavaMethod;

  58 
  59 /**
  60  * Represents the output from compiling a method, including the compiled machine code, associated
  61  * data and references, relocation information, deoptimization information, etc.
  62  */
  63 public class CompilationResult {
  64 
  65     /**
  66      * Provides extra information about instructions or data at specific positions in
  67      * {@link CompilationResult#getTargetCode()}. This is optional information that can be used to
  68      * enhance a disassembly of the code.
  69      */
  70     public abstract static class CodeAnnotation {
  71 
  72         public final int position;
  73 
  74         public CodeAnnotation(int position) {
  75             this.position = position;
  76         }
  77 


 204      */
 205     private byte[] targetCode;
 206 
 207     /**
 208      * The leading number of bytes in {@link #targetCode} containing the emitted machine code.
 209      */
 210     private int targetCodeSize;
 211 
 212     private ArrayList<CodeAnnotation> annotations;
 213 
 214     private Assumption[] assumptions;
 215 
 216     /**
 217      * The list of the methods whose bytecodes were used as input to the compilation. If
 218      * {@code null}, then the compilation did not record method dependencies. Otherwise, the first
 219      * element of this array is the root method of the compilation.
 220      */
 221     private ResolvedJavaMethod[] methods;
 222 
 223     /**





 224      * The list of fields that were accessed from the bytecodes.
 225      */
 226     private ResolvedJavaField[] fields;
 227 
 228     private int bytecodeSize;
 229 
 230     private boolean hasUnsafeAccess;
 231 
 232     private boolean isImmutablePIC;
 233 
 234     public CompilationResult(CompilationIdentifier compilationId) {
 235         this(compilationId, null, false);
 236     }
 237 
 238     public CompilationResult(CompilationIdentifier compilationId, String name) {
 239         this(compilationId, name, false);
 240     }
 241 
 242     public CompilationResult(CompilationIdentifier compilationId, boolean isImmutablePIC) {
 243         this(compilationId, null, isImmutablePIC);


 356             for (ResolvedJavaMethod m : inlinedMethods) {
 357                 methods[i++] = m;
 358             }
 359         }
 360     }
 361 
 362     /**
 363      * Gets the methods whose bytecodes were used as input to the compilation.
 364      *
 365      * The caller must not modify the contents of the returned array.
 366      *
 367      * @return {@code null} if the compilation did not record method dependencies otherwise the
 368      *         methods whose bytecodes were used as input to the compilation with the first element
 369      *         being the root method of the compilation
 370      */
 371     public ResolvedJavaMethod[] getMethods() {
 372         return methods;
 373     }
 374 
 375     /**















 376      * Sets the fields that were referenced from the bytecodes that were used as input to the
 377      * compilation.
 378      *
 379      * @param accessedFields the collected set of fields accessed during compilation
 380      */
 381     public void setFields(EconomicSet<ResolvedJavaField> accessedFields) {
 382         if (accessedFields != null) {
 383             fields = accessedFields.toArray(new ResolvedJavaField[accessedFields.size()]);
 384         }
 385     }
 386 
 387     /**
 388      * Gets the fields that were referenced from bytecodes that were used as input to the
 389      * compilation.
 390      *
 391      * The caller must not modify the contents of the returned array.
 392      *
 393      * @return {@code null} if the compilation did not record fields dependencies otherwise the
 394      *         fields that were accessed from bytecodes were used as input to the compilation.
 395      */


 598         customStackArea = slot;
 599     }
 600 
 601     /**
 602      * @return the machine code generated for this method
 603      */
 604     public byte[] getTargetCode() {
 605         return targetCode;
 606     }
 607 
 608     /**
 609      * @return the size of the machine code generated for this method
 610      */
 611     public int getTargetCodeSize() {
 612         return targetCodeSize;
 613     }
 614 
 615     /**
 616      * @return the code annotations or {@code null} if there are none
 617      */
 618     public List<CodeAnnotation> getAnnotations() {
 619         if (annotations == null) {
 620             return Collections.emptyList();
 621         }
 622         return annotations;
 623     }
 624 
 625     public void addAnnotation(CodeAnnotation annotation) {
 626         checkOpen();
 627         assert annotation != null;
 628         if (annotations == null) {
 629             annotations = new ArrayList<>();
 630         }
 631         annotations.add(annotation);
 632     }
 633 
 634     /**
 635      * @return the list of infopoints, sorted by {@link Site#pcOffset}
 636      */
 637     public List<Infopoint> getInfopoints() {
 638         if (infopoints.isEmpty()) {


 689         return name;
 690     }
 691 
 692     public CompilationIdentifier getCompilationId() {
 693         return compilationId;
 694     }
 695 
 696     public void setHasUnsafeAccess(boolean hasUnsafeAccess) {
 697         checkOpen();
 698         this.hasUnsafeAccess = hasUnsafeAccess;
 699     }
 700 
 701     public boolean hasUnsafeAccess() {
 702         return hasUnsafeAccess;
 703     }
 704 
 705     /**
 706      * Clears the information in this object pertaining to generating code. That is, the
 707      * {@linkplain #getMarks() marks}, {@linkplain #getInfopoints() infopoints},
 708      * {@linkplain #getExceptionHandlers() exception handlers}, {@linkplain #getDataPatches() data
 709      * patches} and {@linkplain #getAnnotations() annotations} recorded in this object are cleared.

 710      */
 711     public void resetForEmittingCode() {
 712         checkOpen();
 713         infopoints.clear();
 714         sourceMapping.clear();
 715         dataPatches.clear();
 716         exceptionHandlers.clear();
 717         marks.clear();
 718         dataSection.clear();
 719         if (annotations != null) {
 720             annotations.clear();
 721         }








 722     }
 723 
 724     private void checkOpen() {
 725         if (closed) {
 726             throw new IllegalStateException();
 727         }
 728     }
 729 
 730     /**
 731      * Closes this compilation result to future updates.
 732      */
 733     public void close() {
 734         if (closed) {
 735             throw new IllegalStateException("Cannot re-close compilation result " + this);
 736         }
 737         dataSection.close();
 738         closed = true;
 739     }
 740 }


  38 import jdk.internal.vm.compiler.collections.EconomicSet;
  39 import org.graalvm.compiler.core.common.CompilationIdentifier;
  40 import org.graalvm.compiler.graph.NodeSourcePosition;
  41 
  42 import jdk.vm.ci.code.DebugInfo;
  43 import jdk.vm.ci.code.StackSlot;
  44 import jdk.vm.ci.code.site.Call;
  45 import jdk.vm.ci.code.site.ConstantReference;
  46 import jdk.vm.ci.code.site.DataPatch;
  47 import jdk.vm.ci.code.site.DataSectionReference;
  48 import jdk.vm.ci.code.site.ExceptionHandler;
  49 import jdk.vm.ci.code.site.Infopoint;
  50 import jdk.vm.ci.code.site.InfopointReason;
  51 import jdk.vm.ci.code.site.Mark;
  52 import jdk.vm.ci.code.site.Reference;
  53 import jdk.vm.ci.code.site.Site;
  54 import jdk.vm.ci.meta.Assumptions.Assumption;
  55 import jdk.vm.ci.meta.InvokeTarget;
  56 import jdk.vm.ci.meta.ResolvedJavaField;
  57 import jdk.vm.ci.meta.ResolvedJavaMethod;
  58 import jdk.vm.ci.meta.SpeculationLog;
  59 
  60 /**
  61  * Represents the output from compiling a method, including the compiled machine code, associated
  62  * data and references, relocation information, deoptimization information, etc.
  63  */
  64 public class CompilationResult {
  65 
  66     /**
  67      * Provides extra information about instructions or data at specific positions in
  68      * {@link CompilationResult#getTargetCode()}. This is optional information that can be used to
  69      * enhance a disassembly of the code.
  70      */
  71     public abstract static class CodeAnnotation {
  72 
  73         public final int position;
  74 
  75         public CodeAnnotation(int position) {
  76             this.position = position;
  77         }
  78 


 205      */
 206     private byte[] targetCode;
 207 
 208     /**
 209      * The leading number of bytes in {@link #targetCode} containing the emitted machine code.
 210      */
 211     private int targetCodeSize;
 212 
 213     private ArrayList<CodeAnnotation> annotations;
 214 
 215     private Assumption[] assumptions;
 216 
 217     /**
 218      * The list of the methods whose bytecodes were used as input to the compilation. If
 219      * {@code null}, then the compilation did not record method dependencies. Otherwise, the first
 220      * element of this array is the root method of the compilation.
 221      */
 222     private ResolvedJavaMethod[] methods;
 223 
 224     /**
 225      * The {@link SpeculationLog} log used during compilation.
 226      */
 227     private SpeculationLog speculationLog;
 228 
 229     /**
 230      * The list of fields that were accessed from the bytecodes.
 231      */
 232     private ResolvedJavaField[] fields;
 233 
 234     private int bytecodeSize;
 235 
 236     private boolean hasUnsafeAccess;
 237 
 238     private boolean isImmutablePIC;
 239 
 240     public CompilationResult(CompilationIdentifier compilationId) {
 241         this(compilationId, null, false);
 242     }
 243 
 244     public CompilationResult(CompilationIdentifier compilationId, String name) {
 245         this(compilationId, name, false);
 246     }
 247 
 248     public CompilationResult(CompilationIdentifier compilationId, boolean isImmutablePIC) {
 249         this(compilationId, null, isImmutablePIC);


 362             for (ResolvedJavaMethod m : inlinedMethods) {
 363                 methods[i++] = m;
 364             }
 365         }
 366     }
 367 
 368     /**
 369      * Gets the methods whose bytecodes were used as input to the compilation.
 370      *
 371      * The caller must not modify the contents of the returned array.
 372      *
 373      * @return {@code null} if the compilation did not record method dependencies otherwise the
 374      *         methods whose bytecodes were used as input to the compilation with the first element
 375      *         being the root method of the compilation
 376      */
 377     public ResolvedJavaMethod[] getMethods() {
 378         return methods;
 379     }
 380 
 381     /**
 382      * Sets the {@link SpeculationLog} log used during compilation.
 383      */
 384     public void setSpeculationLog(SpeculationLog speculationLog) {
 385         checkOpen();
 386         this.speculationLog = speculationLog;
 387     }
 388 
 389     /**
 390      * Gets the {@link SpeculationLog} log, if any, used during compilation.
 391      */
 392     public SpeculationLog getSpeculationLog() {
 393         return speculationLog;
 394     }
 395 
 396     /**
 397      * Sets the fields that were referenced from the bytecodes that were used as input to the
 398      * compilation.
 399      *
 400      * @param accessedFields the collected set of fields accessed during compilation
 401      */
 402     public void setFields(EconomicSet<ResolvedJavaField> accessedFields) {
 403         if (accessedFields != null) {
 404             fields = accessedFields.toArray(new ResolvedJavaField[accessedFields.size()]);
 405         }
 406     }
 407 
 408     /**
 409      * Gets the fields that were referenced from bytecodes that were used as input to the
 410      * compilation.
 411      *
 412      * The caller must not modify the contents of the returned array.
 413      *
 414      * @return {@code null} if the compilation did not record fields dependencies otherwise the
 415      *         fields that were accessed from bytecodes were used as input to the compilation.
 416      */


 619         customStackArea = slot;
 620     }
 621 
 622     /**
 623      * @return the machine code generated for this method
 624      */
 625     public byte[] getTargetCode() {
 626         return targetCode;
 627     }
 628 
 629     /**
 630      * @return the size of the machine code generated for this method
 631      */
 632     public int getTargetCodeSize() {
 633         return targetCodeSize;
 634     }
 635 
 636     /**
 637      * @return the code annotations or {@code null} if there are none
 638      */
 639     public List<CodeAnnotation> getCodeAnnotations() {
 640         if (annotations == null) {
 641             return Collections.emptyList();
 642         }
 643         return annotations;
 644     }
 645 
 646     public void addAnnotation(CodeAnnotation annotation) {
 647         checkOpen();
 648         assert annotation != null;
 649         if (annotations == null) {
 650             annotations = new ArrayList<>();
 651         }
 652         annotations.add(annotation);
 653     }
 654 
 655     /**
 656      * @return the list of infopoints, sorted by {@link Site#pcOffset}
 657      */
 658     public List<Infopoint> getInfopoints() {
 659         if (infopoints.isEmpty()) {


 710         return name;
 711     }
 712 
 713     public CompilationIdentifier getCompilationId() {
 714         return compilationId;
 715     }
 716 
 717     public void setHasUnsafeAccess(boolean hasUnsafeAccess) {
 718         checkOpen();
 719         this.hasUnsafeAccess = hasUnsafeAccess;
 720     }
 721 
 722     public boolean hasUnsafeAccess() {
 723         return hasUnsafeAccess;
 724     }
 725 
 726     /**
 727      * Clears the information in this object pertaining to generating code. That is, the
 728      * {@linkplain #getMarks() marks}, {@linkplain #getInfopoints() infopoints},
 729      * {@linkplain #getExceptionHandlers() exception handlers}, {@linkplain #getDataPatches() data
 730      * patches} and {@linkplain #getCodeAnnotations() annotations} recorded in this object are
 731      * cleared.
 732      */
 733     public void resetForEmittingCode() {
 734         checkOpen();
 735         infopoints.clear();
 736         sourceMapping.clear();
 737         dataPatches.clear();
 738         exceptionHandlers.clear();
 739         marks.clear();
 740         dataSection.clear();
 741         if (annotations != null) {
 742             annotations.clear();
 743         }
 744     }
 745 
 746     public void clearInfopoints() {
 747         infopoints.clear();
 748     }
 749 
 750     public void clearExceptionHandlers() {
 751         exceptionHandlers.clear();
 752     }
 753 
 754     private void checkOpen() {
 755         if (closed) {
 756             throw new IllegalStateException();
 757         }
 758     }
 759 
 760     /**
 761      * Closes this compilation result to future updates.
 762      */
 763     public void close() {
 764         if (closed) {
 765             throw new IllegalStateException("Cannot re-close compilation result " + this);
 766         }
 767         dataSection.close();
 768         closed = true;
 769     }
 770 }
< prev index next >