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