hotspot/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/AOTCompiledClass.java
author iveresov
Tue, 10 Jan 2017 21:39:20 +0300
changeset 43435 01521491ec10
parent 42650 1f304d0c888b
child 46949 44ccdba2d72e
permissions -rw-r--r--
8172310: [AOT] Fix unverified entry point Summary: Fix AOT code for the unverified entry point Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     1
/*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     4
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     8
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    13
 * accompanied this code).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    14
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    18
 *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    21
 * questions.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    22
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    23
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    24
package jdk.tools.jaotc;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    25
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    26
import java.util.ArrayList;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    27
import java.util.HashMap;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    28
import java.util.Map;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    29
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    30
import jdk.tools.jaotc.binformat.BinaryContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    31
import jdk.tools.jaotc.binformat.ReadOnlyDataContainer;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    32
import jdk.tools.jaotc.binformat.Symbol.Binding;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    33
import jdk.tools.jaotc.binformat.Symbol.Kind;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    34
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    35
import jdk.vm.ci.hotspot.HotSpotResolvedObjectType;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    36
import jdk.vm.ci.meta.ResolvedJavaField;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    37
import jdk.vm.ci.meta.ResolvedJavaMethod;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    38
import jdk.vm.ci.meta.ResolvedJavaType;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    39
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    40
/**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    41
 * Class encapsulating Graal-compiled output of a Java class. The compilation result of all methods
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    42
 * of a class {@code className} are maintained in an array list.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    43
 */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    44
public class AOTCompiledClass {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    45
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    46
    public static class AOTKlassData {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    47
        int gotIndex; // Index (offset/8) to the got in the .metaspace.got section
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    48
        int classId;  // Unique ID
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    49
        // Offset to compiled methods data in the .methods.offsets section.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    50
        int compiledMethodsOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    51
        // Offset to dependent methods data.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    52
        int dependentMethodsOffset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    53
        long fingerprint;           // Class fingerprint
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    54
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    55
        private final String name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    56
        private boolean isArray;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    57
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    58
        /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    59
         * List of dependent compiled methods which have a reference to this class.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    60
         */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    61
        private ArrayList<CompiledMethodInfo> dependentMethods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    62
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    63
        public AOTKlassData(BinaryContainer binaryContainer, String name, long fingerprint, int classId) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    64
            this.dependentMethods = new ArrayList<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    65
            this.classId = classId;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    66
            this.fingerprint = fingerprint;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    67
            this.gotIndex = binaryContainer.addTwoSlotMetaspaceSymbol(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    68
            this.compiledMethodsOffset = -1; // Not compiled classes do not have compiled methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    69
            this.dependentMethodsOffset = -1;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    70
            this.name = name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    71
            this.isArray = name.length() > 0 && name.charAt(0) == '[';
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    72
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    73
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    74
        public long getFingerprint() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    75
            return fingerprint;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    76
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    77
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    78
        /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    79
         * Add a method to the list of dependent methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    80
         */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    81
        public synchronized boolean addDependentMethod(CompiledMethodInfo cm) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    82
            return dependentMethods.add(cm);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    83
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    84
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    85
        /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    86
         * Return the array list of dependent class methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    87
         *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    88
         * @return array list of dependent methods
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    89
         */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    90
        public ArrayList<CompiledMethodInfo> getDependentMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    91
            return dependentMethods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    92
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    93
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    94
        /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    95
         * Returns if this class has dependent methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    96
         *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    97
         * @return true if dependent methods exist, false otherwise
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    98
         */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
    99
        public boolean hasDependentMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   100
            return !dependentMethods.isEmpty();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   101
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   102
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   103
        public void setCompiledMethodsOffset(int offset) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   104
            compiledMethodsOffset = offset;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   105
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   106
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   107
        protected void putAOTKlassData(BinaryContainer binaryContainer, ReadOnlyDataContainer container) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   108
            int cntDepMethods = dependentMethods.size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   109
            // Create array of dependent methods IDs. First word is count.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   110
            ReadOnlyDataContainer dependenciesContainer = binaryContainer.getKlassesDependenciesContainer();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   111
            this.dependentMethodsOffset = binaryContainer.addMethodsCount(cntDepMethods, dependenciesContainer);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   112
            for (CompiledMethodInfo methodInfo : dependentMethods) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   113
                dependenciesContainer.appendInt(methodInfo.getCodeId());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   114
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   115
            verify();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   116
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   117
            // @formatter:off
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   118
            /*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   119
             * The offsets layout should match AOTKlassData structure in AOT JVM runtime
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   120
             */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   121
            int offset = container.getByteStreamSize();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   122
            container.createSymbol(offset, Kind.OBJECT, Binding.GLOBAL, 0, name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   123
                      // Add index (offset/8) to the got in the .metaspace.got section
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   124
            container.appendInt(gotIndex).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   125
                      // Add unique ID
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   126
                      appendInt(classId).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   127
                      // Add the offset to compiled methods data in the .metaspace.offsets section.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   128
                      appendInt(compiledMethodsOffset).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   129
                      // Add the offset to dependent methods data in the .metaspace.offsets section.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   130
                      appendInt(dependentMethodsOffset).
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   131
                      // Add fingerprint.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   132
                      appendLong(fingerprint);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   133
            // @formatter:on
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   134
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   135
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   136
        private void verify() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   137
            assert gotIndex > 0 : "incorrect gotIndex: " + gotIndex + " for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   138
            assert isArray || fingerprint != 0 : "incorrect fingerprint: " + fingerprint + " for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   139
            assert compiledMethodsOffset >= -1 : "incorrect compiledMethodsOffset: " + compiledMethodsOffset + " for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   140
            assert dependentMethodsOffset >= -1 : "incorrect dependentMethodsOffset: " + dependentMethodsOffset + " for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   141
            assert classId >= 0 : "incorrect classId: " + classId + " for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   142
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   143
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   144
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   145
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   146
    private final HotSpotResolvedObjectType resolvedJavaType;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   147
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   148
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   149
     * List of all collected class data.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   150
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   151
    private static Map<String, AOTKlassData> klassData = new HashMap<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   152
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   153
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   154
     * List of all methods to be compiled.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   155
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   156
    private ArrayList<ResolvedJavaMethod> methods = new ArrayList<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   157
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   158
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   159
     * List of all compiled class methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   160
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   161
    private ArrayList<CompiledMethodInfo> compiledMethods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   162
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   163
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   164
     * If this class represents Graal stub code.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   165
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   166
    private final boolean representsStubs;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   167
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   168
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   169
     * Classes count used to generate unique global method id.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   170
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   171
    private static int classesCount = 0;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   172
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   173
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   174
     * Construct an object with compiled methods. Intended to be used for code with no corresponding
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   175
     * Java method name in the user application.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   176
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   177
     * @param compiledMethods AOT compiled methods
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   178
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   179
    public AOTCompiledClass(ArrayList<CompiledMethodInfo> compiledMethods) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   180
        this.resolvedJavaType = null;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   181
        this.compiledMethods = compiledMethods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   182
        this.representsStubs = true;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   183
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   184
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   185
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   186
     * Construct an object with compiled versions of the named class.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   187
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   188
    public AOTCompiledClass(ResolvedJavaType resolvedJavaType) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   189
        this.resolvedJavaType = (HotSpotResolvedObjectType) resolvedJavaType;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   190
        this.compiledMethods = new ArrayList<>();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   191
        this.representsStubs = false;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   192
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   193
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   194
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   195
     * @return the ResolvedJavaType of this class
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   196
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   197
    public ResolvedJavaType getResolvedJavaType() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   198
        return resolvedJavaType;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   199
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   200
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   201
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   202
     * Get the list of methods which should be compiled.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   203
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   204
    public ArrayList<ResolvedJavaMethod> getMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   205
        ArrayList<ResolvedJavaMethod> m = methods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   206
        methods = null; // Free - it is not used after that.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   207
        return m;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   208
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   209
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   210
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   211
     * Get the number of all AOT classes.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   212
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   213
    public static int getClassesCount() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   214
        return classesCount;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   215
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   216
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   217
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   218
     * Get the number of methods which should be compiled.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   219
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   220
     * @return number of methods which should be compiled
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   221
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   222
    public int getMethodCount() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   223
        return methods.size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   224
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   225
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   226
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   227
     * Add a method to the list of methods to be compiled.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   228
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   229
    public void addMethod(ResolvedJavaMethod method) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   230
        methods.add(method);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   231
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   232
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   233
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   234
     * Returns if this class has methods which should be compiled.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   235
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   236
     * @return true if this class contains methods which should be compiled, false otherwise
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   237
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   238
    public boolean hasMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   239
        return !methods.isEmpty();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   240
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   241
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   242
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   243
     * Add a method to the list of compiled methods. This method needs to be thread-safe.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   244
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   245
    public synchronized boolean addCompiledMethod(CompiledMethodInfo cm) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   246
        return compiledMethods.add(cm);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   247
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   248
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   249
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   250
     * Return the array list of compiled class methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   251
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   252
     * @return array list of compiled methods
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   253
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   254
    public ArrayList<CompiledMethodInfo> getCompiledMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   255
        return compiledMethods;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   256
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   257
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   258
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   259
     * Returns if this class has successfully compiled methods.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   260
     *
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   261
     * @return true if methods were compiled, false otherwise
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   262
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   263
    public boolean hasCompiledMethods() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   264
        return !compiledMethods.isEmpty();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   265
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   266
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   267
    /**
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   268
     * Add a klass data.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   269
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   270
    public synchronized static AOTKlassData addAOTKlassData(BinaryContainer binaryContainer, HotSpotResolvedObjectType type) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   271
        String name = type.getName();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   272
        long fingerprint = type.getFingerprint();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   273
        AOTKlassData data = klassData.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   274
        if (data != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   275
            assert data.getFingerprint() == fingerprint : "incorrect fingerprint data for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   276
        } else {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   277
            data = new AOTKlassData(binaryContainer, name, fingerprint, classesCount++);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   278
            klassData.put(name, data);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   279
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   280
        return data;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   281
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   282
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   283
    public synchronized static AOTKlassData getAOTKlassData(String name) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   284
        return klassData.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   285
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   286
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   287
    public synchronized static AOTKlassData getAOTKlassData(HotSpotResolvedObjectType type) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   288
        return getAOTKlassData(type.getName());
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   289
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   290
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   291
    public void addAOTKlassData(BinaryContainer binaryContainer) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   292
        for (CompiledMethodInfo methodInfo : compiledMethods) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   293
            // Record methods holder
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   294
            methodInfo.addDependentKlassData(binaryContainer, resolvedJavaType);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   295
            // Record inlinee classes
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   296
            ResolvedJavaMethod[] inlinees = methodInfo.getCompilationResult().getMethods();
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   297
            if (inlinees != null) {
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   298
                for (ResolvedJavaMethod m : inlinees) {
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   299
                    methodInfo.addDependentKlassData(binaryContainer, (HotSpotResolvedObjectType) m.getDeclaringClass());
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   300
                }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   301
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   302
            // Record classes of fields that were accessed
43435
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   303
            ResolvedJavaField[] fields = methodInfo.getCompilationResult().getFields();
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   304
            if (fields != null) {
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   305
                for (ResolvedJavaField f : fields) {
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   306
                    methodInfo.addDependentKlassData(binaryContainer, (HotSpotResolvedObjectType) f.getDeclaringClass());
01521491ec10 8172310: [AOT] Fix unverified entry point
iveresov
parents: 42650
diff changeset
   307
                }
42650
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   308
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   309
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   310
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   311
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   312
    public synchronized static AOTKlassData addFingerprintKlassData(BinaryContainer binaryContainer, HotSpotResolvedObjectType type) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   313
        if (type.isArray()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   314
            return addAOTKlassData(binaryContainer, type);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   315
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   316
        assert type.getFingerprint() != 0 : "no fingerprint for " + type.getName();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   317
        AOTKlassData old = getAOTKlassData(type);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   318
        if (old != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   319
            boolean assertsEnabled = false;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   320
            assert assertsEnabled = true;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   321
            if (assertsEnabled) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   322
                HotSpotResolvedObjectType s = type.getSuperclass();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   323
                if (s != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   324
                    assert getAOTKlassData(s) != null : "fingerprint super " + s.getName() + " needed for " + type.getName();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   325
                }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   326
                for (HotSpotResolvedObjectType i : type.getInterfaces()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   327
                    assert getAOTKlassData(i) != null : "fingerprint super " + i.getName() + " needed for " + type.getName();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   328
                }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   329
            }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   330
            return old;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   331
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   332
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   333
        // Fingerprinting requires super classes and super interfaces
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   334
        HotSpotResolvedObjectType s = type.getSuperclass();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   335
        if (s != null) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   336
            addFingerprintKlassData(binaryContainer, s);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   337
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   338
        for (HotSpotResolvedObjectType i : type.getInterfaces()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   339
            addFingerprintKlassData(binaryContainer, i);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   340
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   341
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   342
        return addAOTKlassData(binaryContainer, type);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   343
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   344
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   345
    /*
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   346
     * Put methods data to contained.
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   347
     */
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   348
    public void putMethodsData(BinaryContainer binaryContainer) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   349
        ReadOnlyDataContainer container = binaryContainer.getMethodsOffsetsContainer();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   350
        int cntMethods = compiledMethods.size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   351
        int startMethods = binaryContainer.addMethodsCount(cntMethods, container);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   352
        for (CompiledMethodInfo methodInfo : compiledMethods) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   353
            methodInfo.addMethodOffsets(binaryContainer, container);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   354
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   355
        String name = resolvedJavaType.getName();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   356
        AOTKlassData data = klassData.get(name);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   357
        assert data != null : "missing data for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   358
        assert data.getFingerprint() == resolvedJavaType.getFingerprint() : "incorrect fingerprint for klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   359
        int cntDepMethods = data.dependentMethods.size();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   360
        assert cntDepMethods > 0 : "no dependent methods for compiled klass: " + name;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   361
        data.setCompiledMethodsOffset(startMethods);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   362
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   363
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   364
    public static void putAOTKlassData(BinaryContainer binaryContainer) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   365
        ReadOnlyDataContainer container = binaryContainer.getKlassesOffsetsContainer();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   366
        for (AOTKlassData data : klassData.values()) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   367
            data.putAOTKlassData(binaryContainer, container);
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   368
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   369
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   370
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   371
    public boolean representsStubs() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   372
        return representsStubs;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   373
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   374
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   375
    public void clear() {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   376
        for (CompiledMethodInfo c : compiledMethods) {
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   377
            c.clear();
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   378
        }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   379
        this.compiledMethods = null;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   380
        this.methods = null;
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   381
    }
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   382
1f304d0c888b 8171008: Integrate AOT compiler into JDK
kvn
parents:
diff changeset
   383
}