src/share/vm/interpreter/bytecode.cpp

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1957
136b78722a08
child 2462
8012aa3ccede
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

duke@435 1 /*
jrose@1934 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "interpreter/bytecode.hpp"
stefank@2314 27 #include "interpreter/linkResolver.hpp"
stefank@2314 28 #include "oops/constantPoolOop.hpp"
stefank@2314 29 #include "oops/oop.inline.hpp"
stefank@2314 30 #include "runtime/fieldType.hpp"
stefank@2314 31 #include "runtime/handles.inline.hpp"
stefank@2314 32 #include "runtime/safepoint.hpp"
stefank@2314 33 #include "runtime/signature.hpp"
duke@435 34
duke@435 35 // Implementation of Bytecode
duke@435 36
jrose@1920 37 bool Bytecode::check_must_rewrite(Bytecodes::Code code) const {
jrose@1920 38 assert(Bytecodes::can_rewrite(code), "post-check only");
duke@435 39
duke@435 40 // Some codes are conditionally rewriting. Look closely at them.
jrose@1920 41 switch (code) {
duke@435 42 case Bytecodes::_aload_0:
duke@435 43 // Even if RewriteFrequentPairs is turned on,
duke@435 44 // the _aload_0 code might delay its rewrite until
duke@435 45 // a following _getfield rewrites itself.
duke@435 46 return false;
duke@435 47
duke@435 48 case Bytecodes::_lookupswitch:
duke@435 49 return false; // the rewrite is not done by the interpreter
duke@435 50
duke@435 51 case Bytecodes::_new:
duke@435 52 // (Could actually look at the class here, but the profit would be small.)
duke@435 53 return false; // the rewrite is not always done
duke@435 54 }
duke@435 55
duke@435 56 // No other special cases.
duke@435 57 return true;
duke@435 58 }
duke@435 59
duke@435 60
jrose@1920 61 #ifdef ASSERT
jrose@1920 62
jrose@1920 63 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const {
jrose@1920 64 Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0));
jrose@1920 65 if (thisbc == Bytecodes::_breakpoint) return; // let the assertion fail silently
jrose@1920 66 if (is_wide) {
jrose@1920 67 assert(thisbc == Bytecodes::_wide, "expected a wide instruction");
jrose@1920 68 thisbc = Bytecodes::cast(byte_at(1));
jrose@1920 69 if (thisbc == Bytecodes::_breakpoint) return;
jrose@1920 70 }
jrose@1920 71 int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 72 int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 73 if (thisflags != testflags)
jrose@1920 74 tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d",
jrose@1920 75 (int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags);
jrose@1920 76 assert(thisflags == testflags, "expected format");
jrose@1920 77 }
jrose@1920 78
jrose@1920 79 void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) {
jrose@1920 80 int have_fmt = (Bytecodes::flags(bc, is_wide)
jrose@1920 81 & (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 |
jrose@1920 82 Bytecodes::_fmt_not_simple |
jrose@1920 83 // Not an offset field:
jrose@1920 84 Bytecodes::_fmt_has_o));
jrose@1920 85 int need_fmt = -1;
jrose@1920 86 switch (size) {
jrose@1920 87 case 1: need_fmt = 0; break;
jrose@1920 88 case 2: need_fmt = Bytecodes::_fmt_has_u2; break;
jrose@1920 89 case 4: need_fmt = Bytecodes::_fmt_has_u4; break;
jrose@1920 90 }
jrose@1920 91 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 92 if (have_fmt != need_fmt) {
jrose@1920 93 tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
jrose@1920 94 assert(have_fmt == need_fmt, "assert_index_size");
jrose@1920 95 }
jrose@1920 96 }
jrose@1920 97
jrose@1920 98 void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) {
jrose@1920 99 int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 100 int need_fmt = -1;
jrose@1920 101 switch (size) {
jrose@1920 102 case 2: need_fmt = Bytecodes::_fmt_bo2; break;
jrose@1920 103 case 4: need_fmt = Bytecodes::_fmt_bo4; break;
jrose@1920 104 }
jrose@1920 105 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 106 if (have_fmt != need_fmt) {
jrose@1920 107 tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
jrose@1920 108 assert(have_fmt == need_fmt, "assert_offset_size");
jrose@1920 109 }
jrose@1920 110 }
jrose@1920 111
jrose@1920 112 void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) {
jrose@1920 113 int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits
jrose@1920 114 // Ignore any 'i' field (for iinc):
jrose@1920 115 & ~Bytecodes::_fmt_has_i);
jrose@1920 116 int need_fmt = -1;
jrose@1920 117 switch (size) {
jrose@1920 118 case 1: need_fmt = Bytecodes::_fmt_bc; break;
jrose@1920 119 case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break;
jrose@1920 120 }
jrose@1920 121 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 122 int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc);
jrose@1920 123 if (have_fmt != need_fmt || where + size != length) {
jrose@1920 124 tty->print_cr("assert_constant_size %d @%d: bc=%d%s %d != %d", size, where, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
jrose@1920 125 }
jrose@1920 126 assert(have_fmt == need_fmt, "assert_constant_size");
jrose@1920 127 assert(where + size == length, "assert_constant_size oob");
jrose@1920 128 }
jrose@1920 129
jrose@1920 130 void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) {
jrose@1920 131 assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index");
jrose@1920 132 }
jrose@1920 133
jrose@1920 134 #endif //ASSERT
duke@435 135
duke@435 136 // Implementation of Bytecode_tableupswitch
duke@435 137
duke@435 138 int Bytecode_tableswitch::dest_offset_at(int i) const {
jrose@1920 139 return get_Java_u4_at(aligned_offset(1 + (3 + i)*jintSize));
duke@435 140 }
duke@435 141
duke@435 142
duke@435 143 // Implementation of Bytecode_invoke
duke@435 144
duke@435 145 void Bytecode_invoke::verify() const {
duke@435 146 assert(is_valid(), "check invoke");
jrose@1920 147 assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter");
duke@435 148 }
duke@435 149
duke@435 150
jrose@1957 151 symbolOop Bytecode_member_ref::signature() const {
duke@435 152 constantPoolOop constants = method()->constants();
duke@435 153 return constants->signature_ref_at(index());
duke@435 154 }
duke@435 155
duke@435 156
jrose@1957 157 symbolOop Bytecode_member_ref::name() const {
duke@435 158 constantPoolOop constants = method()->constants();
duke@435 159 return constants->name_ref_at(index());
duke@435 160 }
duke@435 161
duke@435 162
jrose@1957 163 BasicType Bytecode_member_ref::result_type(Thread *thread) const {
duke@435 164 symbolHandle sh(thread, signature());
duke@435 165 ResultTypeFinder rts(sh);
duke@435 166 rts.iterate();
duke@435 167 return rts.type();
duke@435 168 }
duke@435 169
duke@435 170
duke@435 171 methodHandle Bytecode_invoke::static_target(TRAPS) {
duke@435 172 methodHandle m;
duke@435 173 KlassHandle resolved_klass;
duke@435 174 constantPoolHandle constants(THREAD, _method->constants());
duke@435 175
jrose@1957 176 if (java_code() == Bytecodes::_invokedynamic) {
twisti@1570 177 LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
jrose@1957 178 } else if (java_code() != Bytecodes::_invokeinterface) {
duke@435 179 LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
duke@435 180 } else {
duke@435 181 LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle()));
duke@435 182 }
duke@435 183 return m;
duke@435 184 }
duke@435 185
duke@435 186
jrose@1957 187 int Bytecode_member_ref::index() const {
jrose@1161 188 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4,
jrose@1161 189 // at the same time it allocates per-call-site CP cache entries.
jrose@1957 190 Bytecodes::Code rawc = code();
jrose@1957 191 Bytecode* invoke = bytecode();
jrose@1957 192 if (invoke->has_index_u4(rawc))
jrose@1957 193 return invoke->get_index_u4(rawc);
jrose@1161 194 else
jrose@1957 195 return invoke->get_index_u2_cpcache(rawc);
duke@435 196 }
duke@435 197
jrose@1957 198 int Bytecode_member_ref::pool_index() const {
jrose@1957 199 int index = this->index();
jrose@1957 200 DEBUG_ONLY({
jrose@1957 201 if (!bytecode()->has_index_u4(code()))
jrose@1957 202 index -= constantPoolOopDesc::CPCACHE_INDEX_TAG;
jrose@1957 203 });
jrose@1957 204 return _method->constants()->cache()->entry_at(index)->constant_pool_index();
jrose@1957 205 }
duke@435 206
duke@435 207 // Implementation of Bytecode_field
duke@435 208
duke@435 209 void Bytecode_field::verify() const {
jrose@1957 210 assert(is_valid(), "check field");
duke@435 211 }
duke@435 212
duke@435 213
jrose@1957 214 // Implementation of Bytecode_loadconstant
jrose@1957 215
jrose@1957 216 int Bytecode_loadconstant::raw_index() const {
jrose@1957 217 Bytecode* bcp = bytecode();
jrose@1957 218 Bytecodes::Code rawc = bcp->code();
jrose@1957 219 assert(rawc != Bytecodes::_wide, "verifier prevents this");
jrose@1957 220 if (Bytecodes::java_code(rawc) == Bytecodes::_ldc)
jrose@1957 221 return bcp->get_index_u1(rawc);
jrose@1957 222 else
jrose@1957 223 return bcp->get_index_u2(rawc, false);
duke@435 224 }
duke@435 225
jrose@1957 226 int Bytecode_loadconstant::pool_index() const {
jrose@1957 227 int index = raw_index();
jrose@1957 228 if (has_cache_index()) {
jrose@1957 229 return _method->constants()->cache()->entry_at(index)->constant_pool_index();
jrose@1957 230 }
jrose@1957 231 return index;
duke@435 232 }
duke@435 233
jrose@1957 234 BasicType Bytecode_loadconstant::result_type() const {
jrose@1957 235 int index = pool_index();
jrose@1957 236 constantTag tag = _method->constants()->tag_at(index);
jrose@1957 237 return tag.basic_type();
jrose@1957 238 }
duke@435 239
jrose@1957 240 oop Bytecode_loadconstant::resolve_constant(TRAPS) const {
jrose@1957 241 assert(_method.not_null(), "must supply method to resolve constant");
jrose@1957 242 int index = raw_index();
jrose@1957 243 constantPoolOop constants = _method->constants();
jrose@1957 244 if (has_cache_index()) {
jrose@1957 245 return constants->resolve_cached_constant_at(index, THREAD);
jrose@1957 246 } else {
jrose@1957 247 return constants->resolve_constant_at(index, THREAD);
jrose@1929 248 }
duke@435 249 }
duke@435 250
duke@435 251 //------------------------------------------------------------------------------
duke@435 252 // Non-product code
duke@435 253
duke@435 254 #ifndef PRODUCT
duke@435 255
duke@435 256 void Bytecode_lookupswitch::verify() const {
duke@435 257 switch (Bytecodes::java_code(code())) {
duke@435 258 case Bytecodes::_lookupswitch:
duke@435 259 { int i = number_of_pairs() - 1;
duke@435 260 while (i-- > 0) {
duke@435 261 assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries");
duke@435 262 }
duke@435 263 }
duke@435 264 break;
duke@435 265 default:
duke@435 266 fatal("not a lookupswitch bytecode");
duke@435 267 }
duke@435 268 }
duke@435 269
duke@435 270 void Bytecode_tableswitch::verify() const {
duke@435 271 switch (Bytecodes::java_code(code())) {
duke@435 272 case Bytecodes::_tableswitch:
duke@435 273 { int lo = low_key();
duke@435 274 int hi = high_key();
duke@435 275 assert (hi >= lo, "incorrect hi/lo values in tableswitch");
duke@435 276 int i = hi - lo - 1 ;
duke@435 277 while (i-- > 0) {
duke@435 278 // no special check needed
duke@435 279 }
duke@435 280 }
duke@435 281 break;
duke@435 282 default:
duke@435 283 fatal("not a tableswitch bytecode");
duke@435 284 }
duke@435 285 }
duke@435 286
duke@435 287 #endif

mercurial