src/share/vm/interpreter/rewriter.hpp

Sat, 01 Sep 2012 13:25:18 -0400

author
coleenp
date
Sat, 01 Sep 2012 13:25:18 -0400
changeset 4037
da91efe96a93
parent 3969
1d7922586cf6
child 4133
f6b0eb4e44cf
permissions
-rw-r--r--

6964458: Reimplement class meta-data storage to use native memory
Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes
Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland
Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_INTERPRETER_REWRITER_HPP
stefank@2314 26 #define SHARE_VM_INTERPRETER_REWRITER_HPP
stefank@2314 27
stefank@2314 28 #include "memory/allocation.hpp"
stefank@2314 29 #include "runtime/handles.inline.hpp"
stefank@2314 30 #include "utilities/growableArray.hpp"
stefank@2314 31
duke@435 32 // The Rewriter adds caches to the constant pool and rewrites bytecode indices
duke@435 33 // pointing into the constant pool for better interpreter performance.
duke@435 34
jrose@1161 35 class Rewriter: public StackObj {
duke@435 36 private:
jrose@1161 37 instanceKlassHandle _klass;
jrose@1161 38 constantPoolHandle _pool;
coleenp@4037 39 Array<Method*>* _methods;
jrose@1161 40 intArray _cp_map;
coleenp@4037 41 intStack _cp_cache_map; // for Methodref, Fieldref,
coleenp@4037 42 // InterfaceMethodref and InvokeDynamic
coleenp@4037 43 intArray _reference_map; // maps from cp index to resolved_refs index (or -1)
coleenp@4037 44 intStack _resolved_references_map; // for strings, methodHandle, methodType
coleenp@4037 45 intStack _invokedynamic_references_map; // for invokedynamic resolved refs
twisti@3969 46 intArray _method_handle_invokers;
coleenp@4037 47 int _resolved_reference_limit;
jrose@1161 48
coleenp@4037 49 void init_maps(int length) {
jrose@1161 50 _cp_map.initialize(length, -1);
jrose@1161 51 // Choose an initial value large enough that we don't get frequent
jrose@1161 52 // calls to grow().
jrose@1161 53 _cp_cache_map.initialize(length / 2);
coleenp@4037 54 // Also cache resolved objects, in another different cache.
coleenp@4037 55 _reference_map.initialize(length, -1);
coleenp@4037 56 _resolved_references_map.initialize(length / 2);
coleenp@4037 57 _invokedynamic_references_map.initialize(length / 2);
coleenp@4037 58 _resolved_reference_limit = -1;
coleenp@4037 59 DEBUG_ONLY(_cp_cache_index_limit = -1);
jrose@1161 60 }
coleenp@4037 61
coleenp@4037 62 int _cp_cache_index_limit;
coleenp@4037 63 void record_map_limits() {
coleenp@4037 64 #ifdef ASSERT
coleenp@4037 65 // Record initial size of the two arrays generated for the CP cache:
coleenp@4037 66 _cp_cache_index_limit = _cp_cache_map.length();
coleenp@4037 67 #endif //ASSERT
coleenp@4037 68 _resolved_reference_limit = _resolved_references_map.length();
coleenp@4037 69 }
coleenp@4037 70
jrose@1161 71 int cp_entry_to_cp_cache(int i) { assert(has_cp_cache(i), "oob"); return _cp_map[i]; }
jrose@1161 72 bool has_cp_cache(int i) { return (uint)i < (uint)_cp_map.length() && _cp_map[i] >= 0; }
coleenp@4037 73
jrose@1161 74 int add_cp_cache_entry(int cp_index) {
coleenp@4037 75 assert(_pool->tag_at(cp_index).value() != JVM_CONSTANT_InvokeDynamic, "use indy version");
jrose@1161 76 assert(_cp_map[cp_index] == -1, "not twice on same cp_index");
coleenp@4037 77 assert(_cp_cache_index_limit == -1, "do not add cache entries after first iteration");
jrose@1161 78 int cache_index = _cp_cache_map.append(cp_index);
jrose@1161 79 _cp_map.at_put(cp_index, cache_index);
jrose@1161 80 assert(cp_entry_to_cp_cache(cp_index) == cache_index, "");
coleenp@4037 81 assert(cp_cache_entry_pool_index(cache_index) == cp_index, "");
jrose@1161 82 return cache_index;
jrose@1161 83 }
coleenp@4037 84
coleenp@4037 85 // add a new CP cache entry beyond the normal cache (for invokedynamic only)
coleenp@4037 86 int add_invokedynamic_cp_cache_entry(int cp_index) {
coleenp@4037 87 assert(_pool->tag_at(cp_index).value() == JVM_CONSTANT_InvokeDynamic, "use non-indy version");
coleenp@4037 88 assert(_cp_map[cp_index] == -1, "do not map from cp_index");
coleenp@4037 89 assert(_cp_cache_index_limit >= 0, "add indy cache entries after first iteration");
coleenp@4037 90 int cache_index = _cp_cache_map.append(cp_index);
coleenp@4037 91 assert(cache_index >= _cp_cache_index_limit, "");
coleenp@4037 92 // do not update _cp_map, since the mapping is one-to-many
coleenp@4037 93 assert(cp_cache_entry_pool_index(cache_index) == cp_index, "");
jrose@1494 94 return cache_index;
jrose@1494 95 }
jrose@1161 96
coleenp@4037 97 // fix duplicated code later
coleenp@4037 98 int cp_entry_to_resolved_references(int cp_index) const {
coleenp@4037 99 assert(has_entry_in_resolved_references(cp_index), "oob");
coleenp@4037 100 return _reference_map[cp_index];
coleenp@4037 101 }
coleenp@4037 102 bool has_entry_in_resolved_references(int cp_index) const {
coleenp@4037 103 return (uint)cp_index < (uint)_reference_map.length() && _reference_map[cp_index] >= 0;
coleenp@4037 104 }
coleenp@4037 105
coleenp@4037 106 // add a new entry to the resolved_references map
coleenp@4037 107 int add_resolved_references_entry(int cp_index) {
coleenp@4037 108 assert(_reference_map[cp_index] == -1, "not twice on same cp_index");
coleenp@4037 109 assert(_resolved_reference_limit == -1, "do not add CP refs after first iteration");
coleenp@4037 110 int ref_index = _resolved_references_map.append(cp_index);
coleenp@4037 111 _reference_map.at_put(cp_index, ref_index);
coleenp@4037 112 assert(cp_entry_to_resolved_references(cp_index) == ref_index, "");
coleenp@4037 113 return ref_index;
coleenp@4037 114 }
coleenp@4037 115
coleenp@4037 116 // add a new entry to the resolved_references map (for invokedynamic only)
coleenp@4037 117 int add_invokedynamic_resolved_references_entry(int cp_index, int cache_index) {
coleenp@4037 118 assert(_resolved_reference_limit >= 0, "must add indy refs after first iteration");
coleenp@4037 119 int ref_index = _resolved_references_map.append(cp_index); // many-to-one
coleenp@4037 120 assert(ref_index >= _resolved_reference_limit, "");
coleenp@4037 121 _invokedynamic_references_map.at_put_grow(ref_index, cache_index, -1);
coleenp@4037 122 return ref_index;
coleenp@4037 123 }
coleenp@4037 124
coleenp@4037 125 int resolved_references_entry_to_pool_index(int ref_index) {
coleenp@4037 126 int cp_index = _resolved_references_map[ref_index];
coleenp@4037 127 return cp_index;
coleenp@4037 128 }
coleenp@4037 129
coleenp@4037 130 // invokedynamic support - append the cpCache entry (encoded) in object map.
coleenp@4037 131 // The resolved_references_map should still be in ascending order
coleenp@4037 132 // The resolved_references has the invokedynamic call site objects appended after
coleenp@4037 133 // the objects that are resolved in the constant pool.
coleenp@4037 134 int add_callsite_entry(int main_cpc_entry) {
coleenp@4037 135 int ref_index = _resolved_references_map.append(main_cpc_entry);
coleenp@4037 136 return ref_index;
coleenp@4037 137 }
coleenp@4037 138
jrose@2015 139 // Access the contents of _cp_cache_map to determine CP cache layout.
jrose@2015 140 int cp_cache_entry_pool_index(int cache_index) {
jrose@2015 141 int cp_index = _cp_cache_map[cache_index];
jrose@2015 142 return cp_index;
jrose@2015 143 }
jrose@2015 144
jrose@1161 145 // All the work goes in here:
coleenp@4037 146 Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
jrose@1161 147
jrose@1161 148 void compute_index_maps();
jrose@1161 149 void make_constant_pool_cache(TRAPS);
coleenp@4037 150 void scan_method(Method* m, bool reverse = false);
jrose@1161 151 void rewrite_Object_init(methodHandle m, TRAPS);
coleenp@2945 152 void rewrite_member_reference(address bcp, int offset, bool reverse = false);
coleenp@4037 153 void maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse = false);
coleenp@2945 154 void rewrite_invokedynamic(address bcp, int offset, bool reverse = false);
coleenp@2945 155 void maybe_rewrite_ldc(address bcp, int offset, bool is_wide, bool reverse = false);
coleenp@2945 156 // Revert bytecodes in case of an exception.
coleenp@2945 157 void restore_bytecodes();
duke@435 158
coleenp@2945 159 static methodHandle rewrite_jsrs(methodHandle m, TRAPS);
duke@435 160 public:
jrose@1161 161 // Driver routine:
duke@435 162 static void rewrite(instanceKlassHandle klass, TRAPS);
coleenp@4037 163 static void rewrite(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS);
coleenp@2945 164
coleenp@2945 165 // Second pass, not gated by is_rewritten flag
coleenp@2945 166 static void relocate_and_link(instanceKlassHandle klass, TRAPS);
coleenp@2945 167 // JSR292 version to call with it's own methods.
coleenp@2945 168 static void relocate_and_link(instanceKlassHandle klass,
coleenp@4037 169 Array<Method*>* methods, TRAPS);
coleenp@2945 170
duke@435 171 };
stefank@2314 172
stefank@2314 173 #endif // SHARE_VM_INTERPRETER_REWRITER_HPP

mercurial