Mercurial > hg > truffle
annotate src/share/vm/interpreter/rewriter.cpp @ 7521:d4bc143c575a
replaced use of <br> in javadoc with <p>
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 22 Jan 2013 21:06:57 +0100 |
parents | 989155e2d07a |
children | 5fc51c1ecdeb |
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:
3404
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:
3404
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:
3404
diff
changeset
|
56 case JVM_CONSTANT_Utf8: |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
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:
3404
diff
changeset
|
58 saw_mh_symbol = true; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
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:
3404
diff
changeset
|
69 if (saw_mh_symbol) |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
70 _method_handle_invokers.initialize(length, (int)0); |
0 | 71 } |
72 | |
3404 | 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); |
3404 | 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) { | |
4559
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4138
diff
changeset
|
119 case Bytecodes::_return: |
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4138
diff
changeset
|
120 *bcs.bcp() = Bytecodes::_return_register_finalizer; |
723df37192d6
Make it possible again to build a real client libjvm, drop the UseGraal flag.
Gilles Duboscq <duboscq@ssw.jku.at>
parents:
4138
diff
changeset
|
121 break; |
0 | 122 |
123 case Bytecodes::_istore: | |
124 case Bytecodes::_lstore: | |
125 case Bytecodes::_fstore: | |
126 case Bytecodes::_dstore: | |
127 case Bytecodes::_astore: | |
128 if (bcs.get_index() != 0) continue; | |
129 | |
130 // fall through | |
131 case Bytecodes::_istore_0: | |
132 case Bytecodes::_lstore_0: | |
133 case Bytecodes::_fstore_0: | |
134 case Bytecodes::_dstore_0: | |
135 case Bytecodes::_astore_0: | |
136 THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), | |
137 "can't overwrite local 0 in Object.<init>"); | |
138 break; | |
139 } | |
140 } | |
141 } | |
142 | |
143 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
144 // Rewrite a classfile-order CP index into a native-order CPC index. |
3404 | 145 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
|
146 address p = bcp + offset; |
3404 | 147 if (!reverse) { |
148 int cp_index = Bytes::get_Java_u2(p); | |
149 int cache_index = cp_entry_to_cp_cache(cp_index); | |
150 Bytes::put_native_u2(p, cache_index); | |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
151 if (!_method_handle_invokers.is_empty()) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
152 maybe_rewrite_invokehandle(p - 1, cp_index, cache_index, reverse); |
3404 | 153 } else { |
154 int cache_index = Bytes::get_native_u2(p); | |
155 int pool_index = cp_cache_entry_pool_index(cache_index); | |
156 Bytes::put_Java_u2(p, pool_index); | |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
157 if (!_method_handle_invokers.is_empty()) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
158 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:
3404
diff
changeset
|
159 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
160 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
161 |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
162 |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
163 // 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
|
164 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:
3404
diff
changeset
|
165 if (!reverse) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
166 if ((*opc) == (u1)Bytecodes::_invokevirtual || |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
167 // 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:
3404
diff
changeset
|
168 (*opc) == (u1)Bytecodes::_invokespecial) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
169 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:
3404
diff
changeset
|
170 // Determine whether this is a signature-polymorphic method. |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
171 if (cp_index >= _method_handle_invokers.length()) return; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
172 int status = _method_handle_invokers[cp_index]; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
173 assert(status >= -1 && status <= 1, "oob tri-state"); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
174 if (status == 0) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
175 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:
3404
diff
changeset
|
176 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
|
177 _pool->name_ref_at(cp_index))) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
178 // 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
|
179 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:
3404
diff
changeset
|
180 status = +1; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
181 } else { |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
182 status = -1; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
183 } |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
184 _method_handle_invokers[cp_index] = status; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
185 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
186 // 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:
3404
diff
changeset
|
187 // 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:
3404
diff
changeset
|
188 // 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:
3404
diff
changeset
|
189 if (status > 0) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
190 (*opc) = (u1)Bytecodes::_invokehandle; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
191 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
192 } |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
193 } else { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
194 // Do not need to look at cp_index. |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
195 if ((*opc) == (u1)Bytecodes::_invokehandle) { |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
196 (*opc) = (u1)Bytecodes::_invokevirtual; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
197 // Ignore corner case of original _invokespecial instruction. |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
198 // 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:
3404
diff
changeset
|
199 // (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:
3404
diff
changeset
|
200 } |
3404 | 201 } |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
202 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
203 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
204 |
3404 | 205 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
|
206 address p = bcp + offset; |
3404 | 207 assert(p[-1] == Bytecodes::_invokedynamic, "not invokedynamic bytecode"); |
208 if (!reverse) { | |
209 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
|
210 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
|
211 add_invokedynamic_resolved_references_entries(cp_index, cache_index); |
3404 | 212 // Replace the trailing four bytes with a CPC index for the dynamic |
213 // call site. Unlike other CPC entries, there is one per bytecode, | |
214 // not just one per distinct CP entry. In other words, the | |
215 // CPC-to-CP relation is many-to-one for invokedynamic entries. | |
216 // This means we must use a larger index size than u2 to address | |
217 // all these entries. That is the main reason invokedynamic | |
218 // must have a five-byte instruction format. (Of course, other JVM | |
219 // 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
|
220 Bytes::put_native_u4(p, ConstantPool::encode_invokedynamic_index(cache_index)); |
3404 | 221 // Note: We use native_u4 format exclusively for 4-byte indexes. |
222 } else { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
223 // callsite index |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
224 int cache_index = ConstantPool::decode_invokedynamic_index( |
3404 | 225 Bytes::get_native_u4(p)); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
226 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
|
227 assert(_pool->tag_at(cp_index).is_invoke_dynamic(), "wrong index"); |
3404 | 228 // zero out 4 bytes |
229 Bytes::put_Java_u4(p, 0); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
230 Bytes::put_Java_u2(p, cp_index); |
3404 | 231 } |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
232 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
233 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
234 |
1602 | 235 // Rewrite some ldc bytecodes to _fast_aldc |
3404 | 236 void Rewriter::maybe_rewrite_ldc(address bcp, int offset, bool is_wide, |
237 bool reverse) { | |
238 if (!reverse) { | |
239 assert((*bcp) == (is_wide ? Bytecodes::_ldc_w : Bytecodes::_ldc), "not ldc bytecode"); | |
240 address p = bcp + offset; | |
241 int cp_index = is_wide ? Bytes::get_Java_u2(p) : (u1)(*p); | |
242 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
|
243 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
|
244 int ref_index = cp_entry_to_resolved_references(cp_index); |
3404 | 245 if (is_wide) { |
246 (*bcp) = Bytecodes::_fast_aldc_w; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
247 assert(ref_index == (u2)ref_index, "index overflow"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
248 Bytes::put_native_u2(p, ref_index); |
3404 | 249 } else { |
250 (*bcp) = Bytecodes::_fast_aldc; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
251 assert(ref_index == (u1)ref_index, "index overflow"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
252 (*p) = (u1)ref_index; |
3404 | 253 } |
254 } | |
255 } else { | |
256 Bytecodes::Code rewritten_bc = | |
257 (is_wide ? Bytecodes::_fast_aldc_w : Bytecodes::_fast_aldc); | |
258 if ((*bcp) == rewritten_bc) { | |
259 address p = bcp + offset; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
260 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
|
261 int pool_index = resolved_references_entry_to_pool_index(ref_index); |
3404 | 262 if (is_wide) { |
263 (*bcp) = Bytecodes::_ldc_w; | |
264 assert(pool_index == (u2)pool_index, "index overflow"); | |
265 Bytes::put_Java_u2(p, pool_index); | |
266 } else { | |
267 (*bcp) = Bytecodes::_ldc; | |
268 assert(pool_index == (u1)pool_index, "index overflow"); | |
269 (*p) = (u1)pool_index; | |
270 } | |
1602 | 271 } |
272 } | |
273 } | |
274 | |
275 | |
0 | 276 // 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
|
277 void Rewriter::scan_method(Method* method, bool reverse) { |
0 | 278 |
279 int nof_jsrs = 0; | |
280 bool has_monitor_bytecodes = false; | |
281 | |
282 { | |
283 // 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
|
284 // cached the bytecodes in 'code_base'. If the Method* |
0 | 285 // moves, the bytecodes will also move. |
286 No_Safepoint_Verifier nsv; | |
287 Bytecodes::Code c; | |
288 | |
289 // Bytecodes and their length | |
290 const address code_base = method->code_base(); | |
291 const int code_length = method->code_size(); | |
292 | |
293 int bc_length; | |
294 for (int bci = 0; bci < code_length; bci += bc_length) { | |
295 address bcp = code_base + bci; | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
296 int prefix_length = 0; |
0 | 297 c = (Bytecodes::Code)(*bcp); |
298 | |
299 // Since we have the code, see if we can get the length | |
300 // directly. Some more complicated bytecodes will report | |
301 // a length of zero, meaning we need to make another method | |
302 // call to calculate the length. | |
303 bc_length = Bytecodes::length_for(c); | |
304 if (bc_length == 0) { | |
2142 | 305 bc_length = Bytecodes::length_at(method, bcp); |
0 | 306 |
307 // length_at will put us at the bytecode after the one modified | |
308 // by 'wide'. We don't currently examine any of the bytecodes | |
309 // modified by wide, but in case we do in the future... | |
310 if (c == Bytecodes::_wide) { | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
311 prefix_length = 1; |
0 | 312 c = (Bytecodes::Code)bcp[1]; |
313 } | |
314 } | |
315 | |
316 assert(bc_length != 0, "impossible bytecode length"); | |
317 | |
318 switch (c) { | |
319 case Bytecodes::_lookupswitch : { | |
320 #ifndef CC_INTERP | |
2181 | 321 Bytecode_lookupswitch bc(method, bcp); |
1930 | 322 (*bcp) = ( |
2181 | 323 bc.number_of_pairs() < BinarySwitchThreshold |
1423
760213a60e8b
* rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1138
diff
changeset
|
324 ? Bytecodes::_fast_linearswitch |
760213a60e8b
* rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1138
diff
changeset
|
325 : Bytecodes::_fast_binaryswitch |
760213a60e8b
* rewrite of the code installation
Lukas Stadler <lukas.stadler@oracle.com>
parents:
1138
diff
changeset
|
326 ); |
0 | 327 #endif |
328 break; | |
329 } | |
3404 | 330 case Bytecodes::_fast_linearswitch: |
331 case Bytecodes::_fast_binaryswitch: { | |
332 #ifndef CC_INTERP | |
333 (*bcp) = Bytecodes::_lookupswitch; | |
334 #endif | |
335 break; | |
336 } | |
0 | 337 case Bytecodes::_getstatic : // fall through |
338 case Bytecodes::_putstatic : // fall through | |
339 case Bytecodes::_getfield : // fall through | |
340 case Bytecodes::_putfield : // fall through | |
341 case Bytecodes::_invokevirtual : // fall through | |
342 case Bytecodes::_invokespecial : // fall through | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
343 case Bytecodes::_invokestatic : |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
344 case Bytecodes::_invokeinterface: |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
345 case Bytecodes::_invokehandle : // if reverse=true |
3404 | 346 rewrite_member_reference(bcp, prefix_length+1, reverse); |
0 | 347 break; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
348 case Bytecodes::_invokedynamic: |
3404 | 349 rewrite_invokedynamic(bcp, prefix_length+1, reverse); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
350 break; |
1602 | 351 case Bytecodes::_ldc: |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
352 case Bytecodes::_fast_aldc: // if reverse=true |
3404 | 353 maybe_rewrite_ldc(bcp, prefix_length+1, false, reverse); |
1602 | 354 break; |
355 case Bytecodes::_ldc_w: | |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
3404
diff
changeset
|
356 case Bytecodes::_fast_aldc_w: // if reverse=true |
3404 | 357 maybe_rewrite_ldc(bcp, prefix_length+1, true, reverse); |
1602 | 358 break; |
0 | 359 case Bytecodes::_jsr : // fall through |
360 case Bytecodes::_jsr_w : nof_jsrs++; break; | |
361 case Bytecodes::_monitorenter : // fall through | |
362 case Bytecodes::_monitorexit : has_monitor_bytecodes = true; break; | |
363 } | |
364 } | |
365 } | |
366 | |
367 // Update access flags | |
368 if (has_monitor_bytecodes) { | |
369 method->set_has_monitor_bytecodes(); | |
370 } | |
371 | |
372 // The present of a jsr bytecode implies that the method might potentially | |
373 // have to be rewritten, so we run the oopMapGenerator on the method | |
374 if (nof_jsrs > 0) { | |
375 method->set_has_jsrs(); | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
376 // Second pass will revisit this method. |
3404 | 377 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
|
378 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
379 } |
0 | 380 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
381 // After constant pool is created, revisit methods containing jsrs. |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
382 methodHandle Rewriter::rewrite_jsrs(methodHandle method, TRAPS) { |
3404 | 383 ResourceMark rm(THREAD); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
384 ResolveOopMapConflicts romc(method); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
385 methodHandle original_method = method; |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
386 method = romc.do_potential_rewrite(CHECK_(methodHandle())); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
387 // Update monitor matching info. |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
388 if (romc.monitor_safe()) { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
389 method->set_guaranteed_monitor_matching(); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
390 } |
0 | 391 |
392 return method; | |
393 } | |
394 | |
395 void Rewriter::rewrite(instanceKlassHandle klass, TRAPS) { | |
396 ResourceMark rm(THREAD); | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
397 Rewriter rw(klass, klass->constants(), klass->methods(), CHECK); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
398 // (That's all, folks.) |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
399 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
400 |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
401 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
402 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
|
403 : _klass(klass), |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
404 _pool(cpool), |
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1059
diff
changeset
|
405 _methods(methods) |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
406 { |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
407 assert(_pool->cache() == NULL, "constant pool cache must not be set yet"); |
0 | 408 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
409 // determine index maps for Method* rewriting |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
410 compute_index_maps(); |
0 | 411 |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
412 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
|
413 bool did_rewrite = false; |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
414 int i = _methods->length(); |
0 | 415 while (i-- > 0) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
416 Method* method = _methods->at(i); |
0 | 417 if (method->intrinsic_id() == vmIntrinsics::_Object_init) { |
418 // rewrite the return bytecodes of Object.<init> to register the | |
419 // object for finalization if needed. | |
420 methodHandle m(THREAD, method); | |
421 rewrite_Object_init(m, CHECK); | |
856
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
726
diff
changeset
|
422 did_rewrite = true; |
0 | 423 break; |
424 } | |
425 } | |
856
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
726
diff
changeset
|
426 assert(did_rewrite, "must find Object::<init> to rewrite it"); |
0 | 427 } |
428 | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
429 // rewrite methods, in two passes |
3404 | 430 int len = _methods->length(); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
431 |
3404 | 432 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
|
433 Method* method = _methods->at(i); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
434 scan_method(method); |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
435 } |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
436 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
437 // allocate constant pool cache, now that we've seen all the bytecodes |
3404 | 438 make_constant_pool_cache(THREAD); |
439 | |
440 // Restore bytecodes to their unrewritten state if there are exceptions | |
441 // rewriting bytecodes or allocating the cpCache | |
442 if (HAS_PENDING_EXCEPTION) { | |
443 restore_bytecodes(); | |
444 return; | |
445 } | |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
446 |
7459
cc6a617fffd2
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
6822
diff
changeset
|
447 // 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
|
448 // 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
|
449 // 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
|
450 // Relocated bytecodes don't have to be restored, only the cp cache entries |
3404 | 451 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
|
452 methodHandle m(THREAD, _methods->at(i)); |
726
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
453 |
be93aad57795
6655646: dynamic languages need dynamically linked call sites
jrose
parents:
579
diff
changeset
|
454 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
|
455 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
|
456 // 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
|
457 // 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
|
458 // 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
|
459 if (HAS_PENDING_EXCEPTION) { |
cc6a617fffd2
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
6822
diff
changeset
|
460 restore_bytecodes(); |
cc6a617fffd2
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
6822
diff
changeset
|
461 return; |
cc6a617fffd2
8005494: SIGSEGV in Rewriter::relocate_and_link() when testing Weblogic with CompressedOops and KlassPtrs
coleenp
parents:
6822
diff
changeset
|
462 } |
0 | 463 // Method might have gotten rewritten. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
464 methods->at_put(i, m()); |
0 | 465 } |
466 } | |
467 } |