annotate src/share/vm/interpreter/bytecode.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents a61af66fc99e
children be93aad57795
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 void Bytecode::set_fast_index(int i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
38 assert(0 <= i && i < 0x10000, "illegal index value");
a61af66fc99e Initial load
duke
parents:
diff changeset
39 Bytes::put_native_u2(addr_at(1), (jushort)i);
a61af66fc99e Initial load
duke
parents:
diff changeset
40 }
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42
a61af66fc99e Initial load
duke
parents:
diff changeset
43 bool Bytecode::check_must_rewrite() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
44 assert(Bytecodes::can_rewrite(code()), "post-check only");
a61af66fc99e Initial load
duke
parents:
diff changeset
45
a61af66fc99e Initial load
duke
parents:
diff changeset
46 // Some codes are conditionally rewriting. Look closely at them.
a61af66fc99e Initial load
duke
parents:
diff changeset
47 switch (code()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 case Bytecodes::_aload_0:
a61af66fc99e Initial load
duke
parents:
diff changeset
49 // Even if RewriteFrequentPairs is turned on,
a61af66fc99e Initial load
duke
parents:
diff changeset
50 // the _aload_0 code might delay its rewrite until
a61af66fc99e Initial load
duke
parents:
diff changeset
51 // a following _getfield rewrites itself.
a61af66fc99e Initial load
duke
parents:
diff changeset
52 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
53
a61af66fc99e Initial load
duke
parents:
diff changeset
54 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return false; // the rewrite is not done by the interpreter
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 case Bytecodes::_new:
a61af66fc99e Initial load
duke
parents:
diff changeset
58 // (Could actually look at the class here, but the profit would be small.)
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return false; // the rewrite is not always done
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61
a61af66fc99e Initial load
duke
parents:
diff changeset
62 // No other special cases.
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66
a61af66fc99e Initial load
duke
parents:
diff changeset
67
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // Implementation of Bytecode_tableupswitch
a61af66fc99e Initial load
duke
parents:
diff changeset
69
a61af66fc99e Initial load
duke
parents:
diff changeset
70 int Bytecode_tableswitch::dest_offset_at(int i) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
71 address x = aligned_addr_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
72 int x2 = aligned_offset(1 + (3 + i)*jintSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
73 int val = java_signed_word_at(x2);
a61af66fc99e Initial load
duke
parents:
diff changeset
74 return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize));
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76
a61af66fc99e Initial load
duke
parents:
diff changeset
77
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // Implementation of Bytecode_invoke
a61af66fc99e Initial load
duke
parents:
diff changeset
79
a61af66fc99e Initial load
duke
parents:
diff changeset
80 void Bytecode_invoke::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
81 Bytecodes::Code bc = adjusted_invoke_code();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 assert(is_valid(), "check invoke");
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::signature() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 constantPoolOop constants = method()->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return constants->signature_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 symbolOop Bytecode_invoke::name() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 constantPoolOop constants = method()->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return constants->name_ref_at(index());
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 BasicType Bytecode_invoke::result_type(Thread *thread) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
99 symbolHandle sh(thread, signature());
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ResultTypeFinder rts(sh);
a61af66fc99e Initial load
duke
parents:
diff changeset
101 rts.iterate();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 return rts.type();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 }
a61af66fc99e Initial load
duke
parents:
diff changeset
104
a61af66fc99e Initial load
duke
parents:
diff changeset
105
a61af66fc99e Initial load
duke
parents:
diff changeset
106 methodHandle Bytecode_invoke::static_target(TRAPS) {
a61af66fc99e Initial load
duke
parents:
diff changeset
107 methodHandle m;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 KlassHandle resolved_klass;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 constantPoolHandle constants(THREAD, _method->constants());
a61af66fc99e Initial load
duke
parents:
diff changeset
110
a61af66fc99e Initial load
duke
parents:
diff changeset
111 if (adjusted_invoke_code() != Bytecodes::_invokeinterface) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
a61af66fc99e Initial load
duke
parents:
diff changeset
113 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
a61af66fc99e Initial load
duke
parents:
diff changeset
115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return m;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119
a61af66fc99e Initial load
duke
parents:
diff changeset
120 int Bytecode_invoke::index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return Bytes::get_Java_u2(bcp() + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125 // Implementation of Bytecode_static
a61af66fc99e Initial load
duke
parents:
diff changeset
126
a61af66fc99e Initial load
duke
parents:
diff changeset
127 void Bytecode_static::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic
a61af66fc99e Initial load
duke
parents:
diff changeset
129 || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 BasicType Bytecode_static::result_type(methodOop method) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
134 int index = java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 constantPoolOop constants = method->constants();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 symbolOop field_type = constants->signature_ref_at(index);
a61af66fc99e Initial load
duke
parents:
diff changeset
137 BasicType basic_type = FieldType::basic_type(field_type);
a61af66fc99e Initial load
duke
parents:
diff changeset
138 return basic_type;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // Implementation of Bytecode_field
a61af66fc99e Initial load
duke
parents:
diff changeset
143
a61af66fc99e Initial load
duke
parents:
diff changeset
144 void Bytecode_field::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
145 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
146 assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic ||
a61af66fc99e Initial load
duke
parents:
diff changeset
147 stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field");
a61af66fc99e Initial load
duke
parents:
diff changeset
148 }
a61af66fc99e Initial load
duke
parents:
diff changeset
149
a61af66fc99e Initial load
duke
parents:
diff changeset
150
a61af66fc99e Initial load
duke
parents:
diff changeset
151 bool Bytecode_field::is_static() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
152 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
153 return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic;
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 int Bytecode_field::index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 return java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 }
a61af66fc99e Initial load
duke
parents:
diff changeset
160
a61af66fc99e Initial load
duke
parents:
diff changeset
161
a61af66fc99e Initial load
duke
parents:
diff changeset
162 // Implementation of Bytecodes loac constant
a61af66fc99e Initial load
duke
parents:
diff changeset
163
a61af66fc99e Initial load
duke
parents:
diff changeset
164 int Bytecode_loadconstant::index() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
165 Bytecodes::Code stdc = Bytecodes::java_code(code());
a61af66fc99e Initial load
duke
parents:
diff changeset
166 return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168
a61af66fc99e Initial load
duke
parents:
diff changeset
169 //------------------------------------------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // Non-product code
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 void Bytecode_lookupswitch::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
175 switch (Bytecodes::java_code(code())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
176 case Bytecodes::_lookupswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
177 { int i = number_of_pairs() - 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
178 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
179 assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 }
a61af66fc99e Initial load
duke
parents:
diff changeset
181 }
a61af66fc99e Initial load
duke
parents:
diff changeset
182 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
184 fatal("not a lookupswitch bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
185 }
a61af66fc99e Initial load
duke
parents:
diff changeset
186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 void Bytecode_tableswitch::verify() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
189 switch (Bytecodes::java_code(code())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
190 case Bytecodes::_tableswitch:
a61af66fc99e Initial load
duke
parents:
diff changeset
191 { int lo = low_key();
a61af66fc99e Initial load
duke
parents:
diff changeset
192 int hi = high_key();
a61af66fc99e Initial load
duke
parents:
diff changeset
193 assert (hi >= lo, "incorrect hi/lo values in tableswitch");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 int i = hi - lo - 1 ;
a61af66fc99e Initial load
duke
parents:
diff changeset
195 while (i-- > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // no special check needed
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
199 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
200 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
201 fatal("not a tableswitch bytecode");
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204
a61af66fc99e Initial load
duke
parents:
diff changeset
205 #endif