src/share/vm/interpreter/bytecode.cpp

Mon, 07 Jul 2014 10:12:40 +0200

author
stefank
date
Mon, 07 Jul 2014 10:12:40 +0200
changeset 6992
2c6ef90f030a
parent 4037
da91efe96a93
child 6876
710a3c8b516e
permissions
-rw-r--r--

8049421: G1 Class Unloading after completing a concurrent mark cycle
Reviewed-by: tschatzl, ehelin, brutisso, coleenp, roland, iveresov
Contributed-by: stefan.karlsson@oracle.com, mikael.gerdin@oracle.com

duke@435 1 /*
coleenp@4037 2 * Copyright (c) 1997, 2012, 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"
coleenp@4037 28 #include "oops/constantPool.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 #ifdef ASSERT
jrose@1920 38
jrose@1920 39 void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const {
jrose@1920 40 Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0));
jrose@1920 41 if (thisbc == Bytecodes::_breakpoint) return; // let the assertion fail silently
jrose@1920 42 if (is_wide) {
jrose@1920 43 assert(thisbc == Bytecodes::_wide, "expected a wide instruction");
jrose@1920 44 thisbc = Bytecodes::cast(byte_at(1));
jrose@1920 45 if (thisbc == Bytecodes::_breakpoint) return;
jrose@1920 46 }
jrose@1920 47 int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 48 int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 49 if (thisflags != testflags)
jrose@1920 50 tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d",
jrose@1920 51 (int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags);
jrose@1920 52 assert(thisflags == testflags, "expected format");
jrose@1920 53 }
jrose@1920 54
jrose@1920 55 void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) {
jrose@1920 56 int have_fmt = (Bytecodes::flags(bc, is_wide)
jrose@1920 57 & (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 |
jrose@1920 58 Bytecodes::_fmt_not_simple |
jrose@1920 59 // Not an offset field:
jrose@1920 60 Bytecodes::_fmt_has_o));
jrose@1920 61 int need_fmt = -1;
jrose@1920 62 switch (size) {
jrose@1920 63 case 1: need_fmt = 0; break;
jrose@1920 64 case 2: need_fmt = Bytecodes::_fmt_has_u2; break;
jrose@1920 65 case 4: need_fmt = Bytecodes::_fmt_has_u4; break;
jrose@1920 66 }
jrose@1920 67 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 68 if (have_fmt != need_fmt) {
jrose@1920 69 tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
jrose@1920 70 assert(have_fmt == need_fmt, "assert_index_size");
jrose@1920 71 }
jrose@1920 72 }
jrose@1920 73
jrose@1920 74 void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) {
jrose@1920 75 int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits;
jrose@1920 76 int need_fmt = -1;
jrose@1920 77 switch (size) {
jrose@1920 78 case 2: need_fmt = Bytecodes::_fmt_bo2; break;
jrose@1920 79 case 4: need_fmt = Bytecodes::_fmt_bo4; break;
jrose@1920 80 }
jrose@1920 81 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 82 if (have_fmt != need_fmt) {
jrose@1920 83 tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt);
jrose@1920 84 assert(have_fmt == need_fmt, "assert_offset_size");
jrose@1920 85 }
jrose@1920 86 }
jrose@1920 87
jrose@1920 88 void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) {
jrose@1920 89 int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits
jrose@1920 90 // Ignore any 'i' field (for iinc):
jrose@1920 91 & ~Bytecodes::_fmt_has_i);
jrose@1920 92 int need_fmt = -1;
jrose@1920 93 switch (size) {
jrose@1920 94 case 1: need_fmt = Bytecodes::_fmt_bc; break;
jrose@1920 95 case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break;
jrose@1920 96 }
jrose@1920 97 if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple;
jrose@1920 98 int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc);
jrose@1920 99 if (have_fmt != need_fmt || where + size != length) {
jrose@1920 100 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 101 }
jrose@1920 102 assert(have_fmt == need_fmt, "assert_constant_size");
jrose@1920 103 assert(where + size == length, "assert_constant_size oob");
jrose@1920 104 }
jrose@1920 105
jrose@1920 106 void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) {
jrose@1920 107 assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index");
jrose@1920 108 }
jrose@1920 109
jrose@1920 110 #endif //ASSERT
duke@435 111
duke@435 112 // Implementation of Bytecode_tableupswitch
duke@435 113
duke@435 114 int Bytecode_tableswitch::dest_offset_at(int i) const {
jrose@1920 115 return get_Java_u4_at(aligned_offset(1 + (3 + i)*jintSize));
duke@435 116 }
duke@435 117
duke@435 118
duke@435 119 // Implementation of Bytecode_invoke
duke@435 120
duke@435 121 void Bytecode_invoke::verify() const {
duke@435 122 assert(is_valid(), "check invoke");
twisti@3969 123 assert(cpcache() != NULL, "do not call this from verifier or rewriter");
duke@435 124 }
duke@435 125
duke@435 126
twisti@3969 127 Symbol* Bytecode_member_ref::klass() const {
twisti@3969 128 return constants()->klass_ref_at_noresolve(index());
duke@435 129 }
duke@435 130
duke@435 131
coleenp@2497 132 Symbol* Bytecode_member_ref::name() const {
twisti@3969 133 return constants()->name_ref_at(index());
twisti@3969 134 }
twisti@3969 135
twisti@3969 136
twisti@3969 137 Symbol* Bytecode_member_ref::signature() const {
twisti@3969 138 return constants()->signature_ref_at(index());
duke@435 139 }
duke@435 140
duke@435 141
coleenp@2497 142 BasicType Bytecode_member_ref::result_type() const {
coleenp@2497 143 ResultTypeFinder rts(signature());
duke@435 144 rts.iterate();
duke@435 145 return rts.type();
duke@435 146 }
duke@435 147
duke@435 148
duke@435 149 methodHandle Bytecode_invoke::static_target(TRAPS) {
duke@435 150 methodHandle m;
duke@435 151 KlassHandle resolved_klass;
twisti@3969 152 constantPoolHandle constants(THREAD, this->constants());
duke@435 153
twisti@3969 154 Bytecodes::Code bc = invoke_code();
twisti@3969 155 LinkResolver::resolve_method_statically(m, resolved_klass, bc, constants, index(), CHECK_(methodHandle()));
duke@435 156 return m;
duke@435 157 }
duke@435 158
twisti@3969 159 Handle Bytecode_invoke::appendix(TRAPS) {
twisti@3969 160 ConstantPoolCacheEntry* cpce = cpcache_entry();
twisti@3969 161 if (cpce->has_appendix())
coleenp@4037 162 return Handle(THREAD, cpce->appendix_if_resolved(constants()));
twisti@3969 163 return Handle(); // usual case
twisti@3969 164 }
duke@435 165
jrose@1957 166 int Bytecode_member_ref::index() const {
jrose@1161 167 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4,
jrose@1161 168 // at the same time it allocates per-call-site CP cache entries.
jrose@1957 169 Bytecodes::Code rawc = code();
never@2462 170 if (has_index_u4(rawc))
never@2462 171 return get_index_u4(rawc);
jrose@1161 172 else
never@2462 173 return get_index_u2_cpcache(rawc);
duke@435 174 }
duke@435 175
jrose@1957 176 int Bytecode_member_ref::pool_index() const {
twisti@3969 177 return cpcache_entry()->constant_pool_index();
twisti@3969 178 }
twisti@3969 179
twisti@3969 180 ConstantPoolCacheEntry* Bytecode_member_ref::cpcache_entry() const {
jrose@1957 181 int index = this->index();
coleenp@4037 182 return cpcache()->entry_at(ConstantPool::decode_cpcache_index(index, true));
jrose@1957 183 }
duke@435 184
duke@435 185 // Implementation of Bytecode_field
duke@435 186
duke@435 187 void Bytecode_field::verify() const {
jrose@1957 188 assert(is_valid(), "check field");
duke@435 189 }
duke@435 190
duke@435 191
jrose@1957 192 // Implementation of Bytecode_loadconstant
jrose@1957 193
jrose@1957 194 int Bytecode_loadconstant::raw_index() const {
never@2462 195 Bytecodes::Code rawc = code();
jrose@1957 196 assert(rawc != Bytecodes::_wide, "verifier prevents this");
jrose@1957 197 if (Bytecodes::java_code(rawc) == Bytecodes::_ldc)
never@2462 198 return get_index_u1(rawc);
jrose@1957 199 else
never@2462 200 return get_index_u2(rawc, false);
duke@435 201 }
duke@435 202
jrose@1957 203 int Bytecode_loadconstant::pool_index() const {
jrose@1957 204 int index = raw_index();
jrose@1957 205 if (has_cache_index()) {
coleenp@4037 206 return _method->constants()->object_to_cp_index(index);
jrose@1957 207 }
jrose@1957 208 return index;
duke@435 209 }
duke@435 210
jrose@1957 211 BasicType Bytecode_loadconstant::result_type() const {
jrose@1957 212 int index = pool_index();
jrose@1957 213 constantTag tag = _method->constants()->tag_at(index);
jrose@1957 214 return tag.basic_type();
jrose@1957 215 }
duke@435 216
jrose@1957 217 oop Bytecode_loadconstant::resolve_constant(TRAPS) const {
jrose@1957 218 assert(_method.not_null(), "must supply method to resolve constant");
jrose@1957 219 int index = raw_index();
coleenp@4037 220 ConstantPool* constants = _method->constants();
jrose@1957 221 if (has_cache_index()) {
jrose@1957 222 return constants->resolve_cached_constant_at(index, THREAD);
jrose@1957 223 } else {
jrose@1957 224 return constants->resolve_constant_at(index, THREAD);
jrose@1929 225 }
duke@435 226 }
duke@435 227
duke@435 228 //------------------------------------------------------------------------------
duke@435 229 // Non-product code
duke@435 230
duke@435 231 #ifndef PRODUCT
duke@435 232
duke@435 233 void Bytecode_lookupswitch::verify() const {
duke@435 234 switch (Bytecodes::java_code(code())) {
duke@435 235 case Bytecodes::_lookupswitch:
duke@435 236 { int i = number_of_pairs() - 1;
duke@435 237 while (i-- > 0) {
never@2462 238 assert(pair_at(i).match() < pair_at(i+1).match(), "unsorted table entries");
duke@435 239 }
duke@435 240 }
duke@435 241 break;
duke@435 242 default:
duke@435 243 fatal("not a lookupswitch bytecode");
duke@435 244 }
duke@435 245 }
duke@435 246
duke@435 247 void Bytecode_tableswitch::verify() const {
duke@435 248 switch (Bytecodes::java_code(code())) {
duke@435 249 case Bytecodes::_tableswitch:
duke@435 250 { int lo = low_key();
duke@435 251 int hi = high_key();
duke@435 252 assert (hi >= lo, "incorrect hi/lo values in tableswitch");
duke@435 253 int i = hi - lo - 1 ;
duke@435 254 while (i-- > 0) {
duke@435 255 // no special check needed
duke@435 256 }
duke@435 257 }
duke@435 258 break;
duke@435 259 default:
duke@435 260 fatal("not a tableswitch bytecode");
duke@435 261 }
duke@435 262 }
duke@435 263
duke@435 264 #endif

mercurial