Mercurial > hg > truffle
comparison src/share/vm/interpreter/bytecode.cpp @ 2142:8012aa3ccede
4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed
author | never |
---|---|
date | Thu, 13 Jan 2011 22:15:41 -0800 |
parents | f95d63e2154a |
children | 3582bf76420e |
comparison
equal
deleted
inserted
replaced
2130:34d64ad817f4 | 2142:8012aa3ccede |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
31 #include "runtime/handles.inline.hpp" | 31 #include "runtime/handles.inline.hpp" |
32 #include "runtime/safepoint.hpp" | 32 #include "runtime/safepoint.hpp" |
33 #include "runtime/signature.hpp" | 33 #include "runtime/signature.hpp" |
34 | 34 |
35 // Implementation of Bytecode | 35 // Implementation of Bytecode |
36 | |
37 bool Bytecode::check_must_rewrite(Bytecodes::Code code) const { | |
38 assert(Bytecodes::can_rewrite(code), "post-check only"); | |
39 | |
40 // Some codes are conditionally rewriting. Look closely at them. | |
41 switch (code) { | |
42 case Bytecodes::_aload_0: | |
43 // Even if RewriteFrequentPairs is turned on, | |
44 // the _aload_0 code might delay its rewrite until | |
45 // a following _getfield rewrites itself. | |
46 return false; | |
47 | |
48 case Bytecodes::_lookupswitch: | |
49 return false; // the rewrite is not done by the interpreter | |
50 | |
51 case Bytecodes::_new: | |
52 // (Could actually look at the class here, but the profit would be small.) | |
53 return false; // the rewrite is not always done | |
54 } | |
55 | |
56 // No other special cases. | |
57 return true; | |
58 } | |
59 | |
60 | 36 |
61 #ifdef ASSERT | 37 #ifdef ASSERT |
62 | 38 |
63 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const { | 39 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const { |
64 Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0)); | 40 Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0)); |
186 | 162 |
187 int Bytecode_member_ref::index() const { | 163 int Bytecode_member_ref::index() const { |
188 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, | 164 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
189 // at the same time it allocates per-call-site CP cache entries. | 165 // at the same time it allocates per-call-site CP cache entries. |
190 Bytecodes::Code rawc = code(); | 166 Bytecodes::Code rawc = code(); |
191 Bytecode* invoke = bytecode(); | 167 if (has_index_u4(rawc)) |
192 if (invoke->has_index_u4(rawc)) | 168 return get_index_u4(rawc); |
193 return invoke->get_index_u4(rawc); | |
194 else | 169 else |
195 return invoke->get_index_u2_cpcache(rawc); | 170 return get_index_u2_cpcache(rawc); |
196 } | 171 } |
197 | 172 |
198 int Bytecode_member_ref::pool_index() const { | 173 int Bytecode_member_ref::pool_index() const { |
199 int index = this->index(); | 174 int index = this->index(); |
200 DEBUG_ONLY({ | 175 DEBUG_ONLY({ |
201 if (!bytecode()->has_index_u4(code())) | 176 if (!has_index_u4(code())) |
202 index -= constantPoolOopDesc::CPCACHE_INDEX_TAG; | 177 index -= constantPoolOopDesc::CPCACHE_INDEX_TAG; |
203 }); | 178 }); |
204 return _method->constants()->cache()->entry_at(index)->constant_pool_index(); | 179 return _method->constants()->cache()->entry_at(index)->constant_pool_index(); |
205 } | 180 } |
206 | 181 |
212 | 187 |
213 | 188 |
214 // Implementation of Bytecode_loadconstant | 189 // Implementation of Bytecode_loadconstant |
215 | 190 |
216 int Bytecode_loadconstant::raw_index() const { | 191 int Bytecode_loadconstant::raw_index() const { |
217 Bytecode* bcp = bytecode(); | 192 Bytecodes::Code rawc = code(); |
218 Bytecodes::Code rawc = bcp->code(); | |
219 assert(rawc != Bytecodes::_wide, "verifier prevents this"); | 193 assert(rawc != Bytecodes::_wide, "verifier prevents this"); |
220 if (Bytecodes::java_code(rawc) == Bytecodes::_ldc) | 194 if (Bytecodes::java_code(rawc) == Bytecodes::_ldc) |
221 return bcp->get_index_u1(rawc); | 195 return get_index_u1(rawc); |
222 else | 196 else |
223 return bcp->get_index_u2(rawc, false); | 197 return get_index_u2(rawc, false); |
224 } | 198 } |
225 | 199 |
226 int Bytecode_loadconstant::pool_index() const { | 200 int Bytecode_loadconstant::pool_index() const { |
227 int index = raw_index(); | 201 int index = raw_index(); |
228 if (has_cache_index()) { | 202 if (has_cache_index()) { |
256 void Bytecode_lookupswitch::verify() const { | 230 void Bytecode_lookupswitch::verify() const { |
257 switch (Bytecodes::java_code(code())) { | 231 switch (Bytecodes::java_code(code())) { |
258 case Bytecodes::_lookupswitch: | 232 case Bytecodes::_lookupswitch: |
259 { int i = number_of_pairs() - 1; | 233 { int i = number_of_pairs() - 1; |
260 while (i-- > 0) { | 234 while (i-- > 0) { |
261 assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries"); | 235 assert(pair_at(i).match() < pair_at(i+1).match(), "unsorted table entries"); |
262 } | 236 } |
263 } | 237 } |
264 break; | 238 break; |
265 default: | 239 default: |
266 fatal("not a lookupswitch bytecode"); | 240 fatal("not a lookupswitch bytecode"); |