src/jdk.internal.vm.ci/share/classes/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotInstalledCode.java
changeset 54669 ad45b3802d4e
parent 47216 71c04702a3d5
equal deleted inserted replaced
54668:0bda2308eded 54669:ad45b3802d4e
     1 /*
     1 /*
     2  * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 package jdk.vm.ci.hotspot;
    23 package jdk.vm.ci.hotspot;
    24 
    24 
    25 import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE;
    25 import static jdk.vm.ci.hotspot.CompilerToVM.compilerToVM;
    26 
    26 
    27 import jdk.internal.misc.Unsafe;
       
    28 import jdk.vm.ci.code.InstalledCode;
    27 import jdk.vm.ci.code.InstalledCode;
    29 
    28 
    30 /**
    29 /**
    31  * Implementation of {@link InstalledCode} for HotSpot.
    30  * Implementation of {@link InstalledCode} for HotSpot representing a {@code CodeBlob}. The address
       
    31  * of the {@code CodeBlob} is stored in {@link InstalledCode#address}.
    32  */
    32  */
    33 public abstract class HotSpotInstalledCode extends InstalledCode {
    33 public abstract class HotSpotInstalledCode extends InstalledCode {
    34 
    34 
    35     /**
    35     /**
    36      * Total size of the code blob.
    36      * Total size of the code blob (i.e. {@code CodeBlob::size()}).
    37      */
    37      */
    38     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int size;
    38     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int size;
    39 
    39 
    40     /**
    40     /**
    41      * Start address of the code.
    41      * Start address of the code (i.e. {@code CodeBlob::code_begin()}).
    42      */
    42      */
    43     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private long codeStart;
    43     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private long codeStart;
    44 
    44 
    45     /**
    45     /**
    46      * Size of the code.
    46      * Size of the code (i.e. {@code CodeBlob::code_size()}).
    47      */
    47      */
    48     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int codeSize;
    48     @SuppressFBWarnings(value = "UWF_UNWRITTEN_FIELD", justification = "field is set by the native part") private int codeSize;
    49 
    49 
    50     public HotSpotInstalledCode(String name) {
    50     public HotSpotInstalledCode(String name) {
    51         super(name);
    51         super(name);
    52     }
    52     }
    53 
    53 
    54     /**
    54     /**
    55      * @return the total size of this code blob
    55      * Gets the value of {@code CodeBlob::size()}.
    56      */
    56      */
    57     public int getSize() {
    57     public int getSize() {
    58         return size;
    58         return size;
    59     }
    59     }
    60 
    60 
    61     @Override
    61     @Override
    62     public abstract String toString();
    62     public abstract String toString();
    63 
    63 
       
    64     /**
       
    65      * Gets the value of {@code CodeBlob::code_begin()} if {@linkplain #isValid() valid}, 0
       
    66      * otherwise.
       
    67      */
    64     @Override
    68     @Override
    65     public long getStart() {
    69     public long getStart() {
    66         return codeStart;
    70         return codeStart;
    67     }
    71     }
    68 
    72 
       
    73     /**
       
    74      * Gets the value of {@code CodeBlob::code_size()} if {@linkplain #isValid() valid}, 0
       
    75      * otherwise.
       
    76      */
    69     public long getCodeSize() {
    77     public long getCodeSize() {
    70         return codeSize;
    78         return codeSize;
    71     }
    79     }
    72 
    80 
    73     @Override
    81     @Override
    74     public byte[] getCode() {
    82     public byte[] getCode() {
    75         if (!isValid()) {
    83         return compilerToVM().getCode(this);
    76             return null;
       
    77         }
       
    78         byte[] code = new byte[codeSize];
       
    79         UNSAFE.copyMemory(null, codeStart, code, Unsafe.ARRAY_BYTE_BASE_OFFSET, codeSize);
       
    80         return code;
       
    81     }
    84     }
    82 }
    85 }