annotate src/share/vm/interpreter/bytecode.cpp @ 726:be93aad57795

6655646: dynamic languages need dynamically linked call sites Summary: invokedynamic instruction (JSR 292 RI) Reviewed-by: twisti, never
author jrose
date Tue, 21 Apr 2009 23:21:04 -0700
parents a61af66fc99e
children bd02caa94611
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
a61af66fc99e Initial load
duke
parents:
diff changeset
2 * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved.
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 #include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 #include "incls/_bytecode.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 // Implementation of Bytecode
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // Should eventually get rid of these functions and use ThisRelativeObj methods instead
a61af66fc99e Initial load
duke
parents:
diff changeset
30
a61af66fc99e Initial load
duke
parents:
diff changeset
31 void Bytecode::set_code(Bytecodes::Code code) {
a61af66fc99e Initial load
duke
parents:
diff changeset
32 Bytecodes::check(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
33 *addr_at(0) = u_char(code);
a61af66fc99e Initial load
duke
parents:
diff changeset
34 }
a61af66fc99e Initial load
duke
parents:
diff changeset
35
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 bool Bytecode::check_must_rewrite() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(Bytecodes::can_rewrite(code()), "post-check only");
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Some codes are conditionally rewriting. Look closely at them.
a61af66fc99e Initial load
duke
parents:
diff changeset
41 switch (code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // Even if RewriteFrequentPairs is turned on,
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // the _aload_0 code might delay its rewrite until
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // a following _getfield rewrites itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
46 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 return false; // the rewrite is not done by the interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
50
a61af66fc99e Initial load
duke
parents:
diff changeset
51 case Bytecodes::_new:
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // (Could actually look at the class here, but the profit would be small.)
a61af66fc99e Initial load
duke
parents:
diff changeset
53 return false; // the rewrite is not always done
a61af66fc99e Initial load
duke
parents:
diff changeset
54 }
a61af66fc99e Initial load
duke
parents:
diff changeset
55
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // No other special cases.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 }
a61af66fc99e Initial load
duke
parents:
diff changeset
59
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // Implementation of Bytecode_tableupswitch
a61af66fc99e Initial load
duke
parents:
diff changeset
63
a61af66fc99e Initial load
duke
parents:
diff changeset
64 int Bytecode_tableswitch::dest_offset_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 address x = aligned_addr_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
66 int x2 = aligned_offset(1 + (3 + i)*jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
67 int val = java_signed_word_at(x2);
a61af66fc99e Initial load
duke
parents:
diff changeset
68 return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
69 }
a61af66fc99e Initial load
duke
parents:
diff changeset
70
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Implementation of Bytecode_invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
73
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void Bytecode_invoke::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 Bytecodes::Code bc = adjusted_invoke_code();
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(is_valid(), "check invoke");
a61af66fc99e Initial load
duke
parents:
diff changeset
77 }
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 symbolOop Bytecode_invoke::signature() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 constantPoolOop constants = method()->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 return constants->signature_ref_at(index());
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 symbolOop Bytecode_invoke::name() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 constantPoolOop constants = method()->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return constants->name_ref_at(index());
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 BasicType Bytecode_invoke::result_type(Thread *thread) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 symbolHandle sh(thread, signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
94 ResultTypeFinder rts(sh);
a61af66fc99e Initial load
duke
parents:
diff changeset
95 rts.iterate();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 return rts.type();
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 methodHandle Bytecode_invoke::static_target(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 methodHandle m;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 KlassHandle resolved_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 constantPoolHandle constants(THREAD, _method->constants());
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105 if (adjusted_invoke_code() != Bytecodes::_invokeinterface) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
a61af66fc99e Initial load
duke
parents:
diff changeset
107 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 return m;
a61af66fc99e Initial load
duke
parents:
diff changeset
111 }
a61af66fc99e Initial load
duke
parents:
diff changeset
112
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 int Bytecode_invoke::index() const {
726
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
115 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4,
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
116 // at the same time it allocates per-call-site CP cache entries.
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
117 if (has_giant_index())
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
118 return Bytes::get_native_u4(bcp() + 1);
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
119 else
be93aad57795 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 0
diff changeset
120 return Bytes::get_Java_u2(bcp() + 1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // Implementation of Bytecode_static
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 void Bytecode_static::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
127 assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic
a61af66fc99e Initial load
duke
parents:
diff changeset
128 || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132 BasicType Bytecode_static::result_type(methodOop method) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
133 int index = java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
134 constantPoolOop constants = method->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
135 symbolOop field_type = constants->signature_ref_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
136 BasicType basic_type = FieldType::basic_type(field_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return basic_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // Implementation of Bytecode_field
a61af66fc99e Initial load
duke
parents:
diff changeset
142
a61af66fc99e Initial load
duke
parents:
diff changeset
143 void Bytecode_field::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
145 assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic ||
a61af66fc99e Initial load
duke
parents:
diff changeset
146 stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field");
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150 bool Bytecode_field::is_static() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
152 return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 int Bytecode_field::index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
158 }
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161 // Implementation of Bytecodes loac constant
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 int Bytecode_loadconstant::index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
164 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167
a61af66fc99e Initial load
duke
parents:
diff changeset
168 //------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
170
a61af66fc99e Initial load
duke
parents:
diff changeset
171 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
172
a61af66fc99e Initial load
duke
parents:
diff changeset
173 void Bytecode_lookupswitch::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
174 switch (Bytecodes::java_code(code())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
176 { int i = number_of_pairs() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
177 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
178 assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 }
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
182 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
183 fatal("not a lookupswitch bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
184 }
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186
a61af66fc99e Initial load
duke
parents:
diff changeset
187 void Bytecode_tableswitch::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
188 switch (Bytecodes::java_code(code())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 case Bytecodes::_tableswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
190 { int lo = low_key();
a61af66fc99e Initial load
duke
parents:
diff changeset
191 int hi = high_key();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 assert (hi >= lo, "incorrect hi/lo values in tableswitch");
a61af66fc99e Initial load
duke
parents:
diff changeset
193 int i = hi - lo - 1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
195 // no special check needed
a61af66fc99e Initial load
duke
parents:
diff changeset
196 }
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
199 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
200 fatal("not a tableswitch bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203
a61af66fc99e Initial load
duke
parents:
diff changeset
204 #endif