author | coleenp |
Fri, 22 Feb 2013 08:36:42 -0500 | |
changeset 15799 | 6aa92f9debd2 |
parent 15099 | b31d40895bbb |
child 15928 | f9d5c6e4107f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
15799 | 2 |
* Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4567
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "interpreter/bytecodes.hpp" |
|
27 |
#include "interpreter/interpreter.hpp" |
|
28 |
#include "interpreter/rewriter.hpp" |
|
29 |
#include "memory/gcLocker.hpp" |
|
30 |
#include "memory/resourceArea.hpp" |
|
31 |
#include "oops/generateOopMap.hpp" |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
32 |
#include "prims/methodHandles.hpp" |
1 | 33 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
34 |
// Computes a CPC map (new_index -> original_index) for constant pool entries |
1 | 35 |
// that are referred to by the interpreter at runtime via the constant pool cache. |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
36 |
// Also computes a CP map (original_index -> new_index). |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
37 |
// Marks entries in CP which require additional processing. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
38 |
void Rewriter::compute_index_maps() { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
39 |
const int length = _pool->length(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
40 |
init_maps(length); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
41 |
bool saw_mh_symbol = false; |
1 | 42 |
for (int i = 0; i < length; i++) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
43 |
int tag = _pool->tag_at(i).value(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
44 |
switch (tag) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
45 |
case JVM_CONSTANT_InterfaceMethodref: |
1 | 46 |
case JVM_CONSTANT_Fieldref : // fall through |
47 |
case JVM_CONSTANT_Methodref : // fall through |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
48 |
add_cp_cache_entry(i); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
49 |
break; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
50 |
case JVM_CONSTANT_String: |
5882 | 51 |
case JVM_CONSTANT_MethodHandle : // fall through |
52 |
case JVM_CONSTANT_MethodType : // fall through |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
53 |
add_resolved_references_entry(i); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
54 |
break; |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
55 |
case JVM_CONSTANT_Utf8: |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
56 |
if (_pool->symbol_at(i) == vmSymbols::java_lang_invoke_MethodHandle()) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
57 |
saw_mh_symbol = true; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
58 |
break; |
1 | 59 |
} |
60 |
} |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
61 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
62 |
// Record limits of resolved reference map for constant pool cache indices |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
63 |
record_map_limits(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
64 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
65 |
guarantee((int)_cp_cache_map.length()-1 <= (int)((u2)-1), |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
66 |
"all cp cache indexes fit in a u2"); |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5882
diff
changeset
|
67 |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
68 |
if (saw_mh_symbol) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
69 |
_method_handle_invokers.initialize(length, (int)0); |
1 | 70 |
} |
71 |
||
9971 | 72 |
// Unrewrite the bytecodes if an error occurs. |
73 |
void Rewriter::restore_bytecodes() { |
|
74 |
int len = _methods->length(); |
|
75 |
||
76 |
for (int i = len-1; i >= 0; i--) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
77 |
Method* method = _methods->at(i); |
9971 | 78 |
scan_method(method, true); |
79 |
} |
|
80 |
} |
|
1 | 81 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
82 |
// Creates a constant pool cache given a CPC map |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
83 |
void Rewriter::make_constant_pool_cache(TRAPS) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
84 |
const int length = _cp_cache_map.length(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
85 |
ClassLoaderData* loader_data = _pool->pool_holder()->class_loader_data(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
86 |
ConstantPoolCache* cache = |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
87 |
ConstantPoolCache::allocate(loader_data, length, CHECK); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
88 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
89 |
// initialize object cache in constant pool |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
90 |
_pool->initialize_resolved_references(loader_data, _resolved_references_map, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
91 |
_resolved_reference_limit, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
92 |
CHECK); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
93 |
|
8296
b1c2163e4e59
6912621: iCMS: Error: assert(_markBitMap.isMarked(addr + 1),"Missing Printezis bit?")
ysr
parents:
7913
diff
changeset
|
94 |
No_Safepoint_Verifier nsv; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
95 |
cache->initialize(_cp_cache_map, _invokedynamic_references_map); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
96 |
_pool->set_cache(cache); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
97 |
cache->set_constant_pool(_pool()); |
1 | 98 |
} |
99 |
||
100 |
||
101 |
||
102 |
// The new finalization semantics says that registration of |
|
103 |
// finalizable objects must be performed on successful return from the |
|
104 |
// Object.<init> constructor. We could implement this trivially if |
|
105 |
// <init> were never rewritten but since JVMTI allows this to occur, a |
|
106 |
// more complicated solution is required. A special return bytecode |
|
107 |
// is used only by Object.<init> to signal the finalization |
|
108 |
// registration point. Additionally local 0 must be preserved so it's |
|
109 |
// available to pass to the registration function. For simplicty we |
|
110 |
// require that local 0 is never overwritten so it's available as an |
|
111 |
// argument for registration. |
|
112 |
||
113 |
void Rewriter::rewrite_Object_init(methodHandle method, TRAPS) { |
|
114 |
RawBytecodeStream bcs(method); |
|
115 |
while (!bcs.is_last_bytecode()) { |
|
116 |
Bytecodes::Code opcode = bcs.raw_next(); |
|
117 |
switch (opcode) { |
|
118 |
case Bytecodes::_return: *bcs.bcp() = Bytecodes::_return_register_finalizer; break; |
|
119 |
||
120 |
case Bytecodes::_istore: |
|
121 |
case Bytecodes::_lstore: |
|
122 |
case Bytecodes::_fstore: |
|
123 |
case Bytecodes::_dstore: |
|
124 |
case Bytecodes::_astore: |
|
125 |
if (bcs.get_index() != 0) continue; |
|
126 |
||
127 |
// fall through |
|
128 |
case Bytecodes::_istore_0: |
|
129 |
case Bytecodes::_lstore_0: |
|
130 |
case Bytecodes::_fstore_0: |
|
131 |
case Bytecodes::_dstore_0: |
|
132 |
case Bytecodes::_astore_0: |
|
133 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), |
|
134 |
"can't overwrite local 0 in Object.<init>"); |
|
135 |
break; |
|
136 |
} |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
141 |
// Rewrite a classfile-order CP index into a native-order CPC index. |
9971 | 142 |
void Rewriter::rewrite_member_reference(address bcp, int offset, bool reverse) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
143 |
address p = bcp + offset; |
9971 | 144 |
if (!reverse) { |
145 |
int cp_index = Bytes::get_Java_u2(p); |
|
146 |
int cache_index = cp_entry_to_cp_cache(cp_index); |
|
147 |
Bytes::put_native_u2(p, cache_index); |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
148 |
if (!_method_handle_invokers.is_empty()) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
149 |
maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse); |
9971 | 150 |
} else { |
151 |
int cache_index = Bytes::get_native_u2(p); |
|
152 |
int pool_index = cp_cache_entry_pool_index(cache_index); |
|
153 |
Bytes::put_Java_u2(p, pool_index); |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
154 |
if (!_method_handle_invokers.is_empty()) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
155 |
maybe_rewrite_invokehandle(p - 1, pool_index, cache_index, reverse); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
156 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
157 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
158 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
159 |
|
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
160 |
// Adjust the invocation bytecode for a signature-polymorphic method (MethodHandle.invoke, etc.) |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
161 |
void Rewriter::maybe_rewrite_invokehandle(address opc, int cp_index, int cache_index, bool reverse) { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
162 |
if (!reverse) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
163 |
if ((*opc) == (u1)Bytecodes::_invokevirtual || |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
164 |
// allow invokespecial as an alias, although it would be very odd: |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
165 |
(*opc) == (u1)Bytecodes::_invokespecial) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
166 |
assert(_pool->tag_at(cp_index).is_method(), "wrong index"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
167 |
// Determine whether this is a signature-polymorphic method. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
168 |
if (cp_index >= _method_handle_invokers.length()) return; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
169 |
int status = _method_handle_invokers[cp_index]; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
170 |
assert(status >= -1 && status <= 1, "oob tri-state"); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
171 |
if (status == 0) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
172 |
if (_pool->klass_ref_at_noresolve(cp_index) == vmSymbols::java_lang_invoke_MethodHandle() && |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
173 |
MethodHandles::is_signature_polymorphic_name(SystemDictionary::MethodHandle_klass(), |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
174 |
_pool->name_ref_at(cp_index))) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
175 |
// we may need a resolved_refs entry for the appendix |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13728
diff
changeset
|
176 |
add_invokedynamic_resolved_references_entries(cp_index, cache_index); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
177 |
status = +1; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
178 |
} else { |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
179 |
status = -1; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
180 |
} |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
181 |
_method_handle_invokers[cp_index] = status; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
182 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
183 |
// We use a special internal bytecode for such methods (if non-static). |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
184 |
// The basic reason for this is that such methods need an extra "appendix" argument |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
185 |
// to transmit the call site's intended call type. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
186 |
if (status > 0) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
187 |
(*opc) = (u1)Bytecodes::_invokehandle; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
188 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
189 |
} |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
190 |
} else { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
191 |
// Do not need to look at cp_index. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
192 |
if ((*opc) == (u1)Bytecodes::_invokehandle) { |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
193 |
(*opc) = (u1)Bytecodes::_invokevirtual; |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
194 |
// Ignore corner case of original _invokespecial instruction. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
195 |
// This is safe because (a) the signature polymorphic method was final, and |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
196 |
// (b) the implementation of MethodHandle will not call invokespecial on it. |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
197 |
} |
9971 | 198 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
199 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
200 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
201 |
|
9971 | 202 |
void Rewriter::rewrite_invokedynamic(address bcp, int offset, bool reverse) { |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
203 |
address p = bcp + offset; |
9971 | 204 |
assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode"); |
205 |
if (!reverse) { |
|
206 |
int cp_index = Bytes::get_Java_u2(p); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
207 |
int cache_index = add_invokedynamic_cp_cache_entry(cp_index); |
13929
8da0dc50a6e4
7200949: JSR 292: rubybench/bench/time/bench_base64.rb fails with jruby.jar not on boot class path
twisti
parents:
13728
diff
changeset
|
208 |
add_invokedynamic_resolved_references_entries(cp_index, cache_index); |
9971 | 209 |
// Replace the trailing four bytes with a CPC index for the dynamic |
210 |
// call site. Unlike other CPC entries, there is one per bytecode, |
|
211 |
// not just one per distinct CP entry. In other words, the |
|
212 |
// CPC-to-CP relation is many-to-one for invokedynamic entries. |
|
213 |
// This means we must use a larger index size than u2 to address |
|
214 |
// all these entries. That is the main reason invokedynamic |
|
215 |
// must have a five-byte instruction format. (Of course, other JVM |
|
216 |
// implementations can use the bytes for other purposes.) |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
217 |
Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index)); |
9971 | 218 |
// Note: We use native_u4 format exclusively for 4-byte indexes. |
219 |
} else { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
220 |
// callsite index |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
221 |
int cache_index = ConstantPool::decode_invokedynamic_index( |
9971 | 222 |
Bytes::get_native_u4(p)); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
223 |
int cp_index = cp_cache_entry_pool_index(cache_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
224 |
assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index"); |
9971 | 225 |
// zero out 4 bytes |
226 |
Bytes::put_Java_u4(p, 0); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
227 |
Bytes::put_Java_u2(p, cp_index); |
9971 | 228 |
} |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
229 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
230 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
231 |
|
5882 | 232 |
// Rewrite some ldc bytecodes to _fast_aldc |
9971 | 233 |
void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide, |
234 |
bool reverse) { |
|
235 |
if (!reverse) { |
|
236 |
assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode"); |
|
237 |
address p = bcp + offset; |
|
238 |
int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p); |
|
239 |
constantTag tag = _pool->tag_at(cp_index).value(); |
|
15799 | 240 |
if (tag.is_method_handle() || tag.is_method_type() || tag.is_string()) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
241 |
int ref_index = cp_entry_to_resolved_references(cp_index); |
9971 | 242 |
if (is_wide) { |
243 |
(*bcp) = Bytecodes::_fast_aldc_w; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
244 |
assert(ref_index == (u2)ref_index, "index overflow"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
245 |
Bytes::put_native_u2(p, ref_index); |
9971 | 246 |
} else { |
247 |
(*bcp) = Bytecodes::_fast_aldc; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
248 |
assert(ref_index == (u1)ref_index, "index overflow"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
249 |
(*p) = (u1)ref_index; |
9971 | 250 |
} |
251 |
} |
|
252 |
} else { |
|
253 |
Bytecodes::Code rewritten_bc = |
|
254 |
(is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc); |
|
255 |
if ((*bcp) == rewritten_bc) { |
|
256 |
address p = bcp + offset; |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
257 |
int ref_index = is_wide ? Bytes::get_native_u2(p) : (u1)(*p); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
258 |
int pool_index = resolved_references_entry_to_pool_index(ref_index); |
9971 | 259 |
if (is_wide) { |
260 |
(*bcp) = Bytecodes::_ldc_w; |
|
261 |
assert(pool_index == (u2)pool_index, "index overflow"); |
|
262 |
Bytes::put_Java_u2(p, pool_index); |
|
263 |
} else { |
|
264 |
(*bcp) = Bytecodes::_ldc; |
|
265 |
assert(pool_index == (u1)pool_index, "index overflow"); |
|
266 |
(*p) = (u1)pool_index; |
|
267 |
} |
|
5882 | 268 |
} |
269 |
} |
|
270 |
} |
|
271 |
||
272 |
||
1 | 273 |
// Rewrites a method given the index_map information |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
274 |
void Rewriter::scan_method(Method* method, bool reverse) { |
1 | 275 |
|
276 |
int nof_jsrs = 0; |
|
277 |
bool has_monitor_bytecodes = false; |
|
278 |
||
279 |
{ |
|
280 |
// We cannot tolerate a GC in this block, because we've |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
281 |
// cached the bytecodes in 'code_base'. If the Method* |
1 | 282 |
// moves, the bytecodes will also move. |
283 |
No_Safepoint_Verifier nsv; |
|
284 |
Bytecodes::Code c; |
|
285 |
||
286 |
// Bytecodes and their length |
|
287 |
const address code_base = method->code_base(); |
|
288 |
const int code_length = method->code_size(); |
|
289 |
||
290 |
int bc_length; |
|
291 |
for (int bci = 0; bci < code_length; bci += bc_length) { |
|
292 |
address bcp = code_base + bci; |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
293 |
int prefix_length = 0; |
1 | 294 |
c = (Bytecodes::Code)(*bcp); |
295 |
||
296 |
// Since we have the code, see if we can get the length |
|
297 |
// directly. Some more complicated bytecodes will report |
|
298 |
// a length of zero, meaning we need to make another method |
|
299 |
// call to calculate the length. |
|
300 |
bc_length = Bytecodes::length_for(c); |
|
301 |
if (bc_length == 0) { |
|
7913 | 302 |
bc_length = Bytecodes::length_at(method, bcp); |
1 | 303 |
|
304 |
// length_at will put us at the bytecode after the one modified |
|
305 |
// by 'wide'. We don't currently examine any of the bytecodes |
|
306 |
// modified by wide, but in case we do in the future... |
|
307 |
if (c == Bytecodes::_wide) { |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
308 |
prefix_length = 1; |
1 | 309 |
c = (Bytecodes::Code)bcp[1]; |
310 |
} |
|
311 |
} |
|
312 |
||
313 |
assert(bc_length != 0, "impossible bytecode length"); |
|
314 |
||
315 |
switch (c) { |
|
316 |
case Bytecodes::_lookupswitch : { |
|
317 |
#ifndef CC_INTERP |
|
7913 | 318 |
Bytecode_lookupswitch bc(method, bcp); |
5688 | 319 |
(*bcp) = ( |
7913 | 320 |
bc.number_of_pairs() < BinarySwitchThreshold |
1 | 321 |
? Bytecodes::_fast_linearswitch |
322 |
: Bytecodes::_fast_binaryswitch |
|
323 |
); |
|
324 |
#endif |
|
325 |
break; |
|
326 |
} |
|
9971 | 327 |
case Bytecodes::_fast_linearswitch: |
328 |
case Bytecodes::_fast_binaryswitch: { |
|
329 |
#ifndef CC_INTERP |
|
330 |
(*bcp) = Bytecodes::_lookupswitch; |
|
331 |
#endif |
|
332 |
break; |
|
333 |
} |
|
1 | 334 |
case Bytecodes::_getstatic : // fall through |
335 |
case Bytecodes::_putstatic : // fall through |
|
336 |
case Bytecodes::_getfield : // fall through |
|
337 |
case Bytecodes::_putfield : // fall through |
|
338 |
case Bytecodes::_invokevirtual : // fall through |
|
339 |
case Bytecodes::_invokespecial : // fall through |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
340 |
case Bytecodes::_invokestatic : |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
341 |
case Bytecodes::_invokeinterface: |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
342 |
case Bytecodes::_invokehandle : // if reverse=true |
9971 | 343 |
rewrite_member_reference(bcp, prefix_length+1, reverse); |
1 | 344 |
break; |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
345 |
case Bytecodes::_invokedynamic: |
9971 | 346 |
rewrite_invokedynamic(bcp, prefix_length+1, reverse); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
347 |
break; |
5882 | 348 |
case Bytecodes::_ldc: |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
349 |
case Bytecodes::_fast_aldc: // if reverse=true |
9971 | 350 |
maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse); |
5882 | 351 |
break; |
352 |
case Bytecodes::_ldc_w: |
|
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
9971
diff
changeset
|
353 |
case Bytecodes::_fast_aldc_w: // if reverse=true |
9971 | 354 |
maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse); |
5882 | 355 |
break; |
1 | 356 |
case Bytecodes::_jsr : // fall through |
357 |
case Bytecodes::_jsr_w : nof_jsrs++; break; |
|
358 |
case Bytecodes::_monitorenter : // fall through |
|
359 |
case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break; |
|
360 |
} |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
// Update access flags |
|
365 |
if (has_monitor_bytecodes) { |
|
366 |
method->set_has_monitor_bytecodes(); |
|
367 |
} |
|
368 |
||
369 |
// The present of a jsr bytecode implies that the method might potentially |
|
370 |
// have to be rewritten, so we run the oopMapGenerator on the method |
|
371 |
if (nof_jsrs > 0) { |
|
372 |
method->set_has_jsrs(); |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
373 |
// Second pass will revisit this method. |
9971 | 374 |
assert(method->has_jsrs(), "didn't we just set this?"); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
375 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
376 |
} |
1 | 377 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
378 |
// After constant pool is created, revisit methods containing jsrs. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
379 |
methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) { |
9971 | 380 |
ResourceMark rm(THREAD); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
381 |
ResolveOopMapConflicts romc(method); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
382 |
methodHandle original_method = method; |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
383 |
method = romc.do_potential_rewrite(CHECK_(methodHandle())); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
384 |
// Update monitor matching info. |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
385 |
if (romc.monitor_safe()) { |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
386 |
method->set_guaranteed_monitor_matching(); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
387 |
} |
1 | 388 |
|
389 |
return method; |
|
390 |
} |
|
391 |
||
392 |
void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) { |
|
393 |
ResourceMark rm(THREAD); |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
394 |
Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
395 |
// (That's all, folks.) |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
396 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
397 |
|
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
398 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
399 |
Rewriter::Rewriter(instanceKlassHandle klass, constantPoolHandle cpool, Array<Method*>* methods, TRAPS) |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
400 |
: _klass(klass), |
4567
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
401 |
_pool(cpool), |
7fc02fbe5c7a
6893268: additional dynamic language related optimizations in C2
twisti
parents:
4429
diff
changeset
|
402 |
_methods(methods) |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
403 |
{ |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
404 |
assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); |
1 | 405 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
406 |
// determine index maps for Method* rewriting |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
407 |
compute_index_maps(); |
1 | 408 |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
409 |
if (RegisterFinalizersAtInit && _klass->name() == vmSymbols::java_lang_Object()) { |
3273
6acf7084b1d3
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
2570
diff
changeset
|
410 |
bool did_rewrite = false; |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
411 |
int i = _methods->length(); |
1 | 412 |
while (i-- > 0) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
413 |
Method* method = _methods->at(i); |
1 | 414 |
if (method->intrinsic_id() == vmIntrinsics::_Object_init) { |
415 |
// rewrite the return bytecodes of Object.<init> to register the |
|
416 |
// object for finalization if needed. |
|
417 |
methodHandle m(THREAD, method); |
|
418 |
rewrite_Object_init(m, CHECK); |
|
3273
6acf7084b1d3
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
2570
diff
changeset
|
419 |
did_rewrite = true; |
1 | 420 |
break; |
421 |
} |
|
422 |
} |
|
3273
6acf7084b1d3
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
2570
diff
changeset
|
423 |
assert(did_rewrite, "must find Object::<init> to rewrite it"); |
1 | 424 |
} |
425 |
||
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
426 |
// rewrite methods, in two passes |
9971 | 427 |
int len = _methods->length(); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
428 |
|
9971 | 429 |
for (int i = len-1; i >= 0; i--) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
430 |
Method* method = _methods->at(i); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
431 |
scan_method(method); |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
432 |
} |
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
433 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
434 |
// allocate constant pool cache, now that we've seen all the bytecodes |
9971 | 435 |
make_constant_pool_cache(THREAD); |
436 |
||
437 |
// Restore bytecodes to their unrewritten state if there are exceptions |
|
438 |
// rewriting bytecodes or allocating the cpCache |
|
439 |
if (HAS_PENDING_EXCEPTION) { |
|
440 |
restore_bytecodes(); |
|
441 |
return; |
|
442 |
} |
|
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
443 |
|
15099
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
444 |
// Relocate after everything, but still do this under the is_rewritten flag, |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
445 |
// so methods with jsrs in custom class lists in aren't attempted to be |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
446 |
// rewritten in the RO section of the shared archive. |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
447 |
// Relocated bytecodes don't have to be restored, only the cp cache entries |
9971 | 448 |
for (int i = len-1; i >= 0; i--) { |
15099
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
449 |
methodHandle m(THREAD, _methods->at(i)); |
2570
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
450 |
|
ecc7862946d4
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
2105
diff
changeset
|
451 |
if (m->has_jsrs()) { |
15099
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
452 |
m = rewrite_jsrs(m, THREAD); |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
453 |
// Restore bytecodes to their unrewritten state if there are exceptions |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
454 |
// relocating bytecodes. If some are relocated, that is ok because that |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
455 |
// doesn't affect constant pool to cpCache rewriting. |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
456 |
if (HAS_PENDING_EXCEPTION) { |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
457 |
restore_bytecodes(); |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
458 |
return; |
b31d40895bbb
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
13929
diff
changeset
|
459 |
} |
1 | 460 |
// Method might have gotten rewritten. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
461 |
methods->at_put(i, m()); |
1 | 462 |
} |
463 |
} |
|
464 |
} |