Wed, 12 Mar 2008 18:07:46 -0700
6599425: 4/3 OopMapCache::lookup() can cause later crash or assert() failure
Summary: Add should_not_be_cached() to markOop and methodOop and query that status inOopMapCache::lookup()
Reviewed-by: coleenp, sspitsyn, jmasa
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2002 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_bytecode.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // Implementation of Bytecode |
duke@435 | 29 | // Should eventually get rid of these functions and use ThisRelativeObj methods instead |
duke@435 | 30 | |
duke@435 | 31 | void Bytecode::set_code(Bytecodes::Code code) { |
duke@435 | 32 | Bytecodes::check(code); |
duke@435 | 33 | *addr_at(0) = u_char(code); |
duke@435 | 34 | } |
duke@435 | 35 | |
duke@435 | 36 | |
duke@435 | 37 | void Bytecode::set_fast_index(int i) { |
duke@435 | 38 | assert(0 <= i && i < 0x10000, "illegal index value"); |
duke@435 | 39 | Bytes::put_native_u2(addr_at(1), (jushort)i); |
duke@435 | 40 | } |
duke@435 | 41 | |
duke@435 | 42 | |
duke@435 | 43 | bool Bytecode::check_must_rewrite() const { |
duke@435 | 44 | assert(Bytecodes::can_rewrite(code()), "post-check only"); |
duke@435 | 45 | |
duke@435 | 46 | // Some codes are conditionally rewriting. Look closely at them. |
duke@435 | 47 | switch (code()) { |
duke@435 | 48 | case Bytecodes::_aload_0: |
duke@435 | 49 | // Even if RewriteFrequentPairs is turned on, |
duke@435 | 50 | // the _aload_0 code might delay its rewrite until |
duke@435 | 51 | // a following _getfield rewrites itself. |
duke@435 | 52 | return false; |
duke@435 | 53 | |
duke@435 | 54 | case Bytecodes::_lookupswitch: |
duke@435 | 55 | return false; // the rewrite is not done by the interpreter |
duke@435 | 56 | |
duke@435 | 57 | case Bytecodes::_new: |
duke@435 | 58 | // (Could actually look at the class here, but the profit would be small.) |
duke@435 | 59 | return false; // the rewrite is not always done |
duke@435 | 60 | } |
duke@435 | 61 | |
duke@435 | 62 | // No other special cases. |
duke@435 | 63 | return true; |
duke@435 | 64 | } |
duke@435 | 65 | |
duke@435 | 66 | |
duke@435 | 67 | |
duke@435 | 68 | // Implementation of Bytecode_tableupswitch |
duke@435 | 69 | |
duke@435 | 70 | int Bytecode_tableswitch::dest_offset_at(int i) const { |
duke@435 | 71 | address x = aligned_addr_at(1); |
duke@435 | 72 | int x2 = aligned_offset(1 + (3 + i)*jintSize); |
duke@435 | 73 | int val = java_signed_word_at(x2); |
duke@435 | 74 | return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize)); |
duke@435 | 75 | } |
duke@435 | 76 | |
duke@435 | 77 | |
duke@435 | 78 | // Implementation of Bytecode_invoke |
duke@435 | 79 | |
duke@435 | 80 | void Bytecode_invoke::verify() const { |
duke@435 | 81 | Bytecodes::Code bc = adjusted_invoke_code(); |
duke@435 | 82 | assert(is_valid(), "check invoke"); |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | |
duke@435 | 86 | symbolOop Bytecode_invoke::signature() const { |
duke@435 | 87 | constantPoolOop constants = method()->constants(); |
duke@435 | 88 | return constants->signature_ref_at(index()); |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | |
duke@435 | 92 | symbolOop Bytecode_invoke::name() const { |
duke@435 | 93 | constantPoolOop constants = method()->constants(); |
duke@435 | 94 | return constants->name_ref_at(index()); |
duke@435 | 95 | } |
duke@435 | 96 | |
duke@435 | 97 | |
duke@435 | 98 | BasicType Bytecode_invoke::result_type(Thread *thread) const { |
duke@435 | 99 | symbolHandle sh(thread, signature()); |
duke@435 | 100 | ResultTypeFinder rts(sh); |
duke@435 | 101 | rts.iterate(); |
duke@435 | 102 | return rts.type(); |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | |
duke@435 | 106 | methodHandle Bytecode_invoke::static_target(TRAPS) { |
duke@435 | 107 | methodHandle m; |
duke@435 | 108 | KlassHandle resolved_klass; |
duke@435 | 109 | constantPoolHandle constants(THREAD, _method->constants()); |
duke@435 | 110 | |
duke@435 | 111 | if (adjusted_invoke_code() != Bytecodes::_invokeinterface) { |
duke@435 | 112 | LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 113 | } else { |
duke@435 | 114 | LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 115 | } |
duke@435 | 116 | return m; |
duke@435 | 117 | } |
duke@435 | 118 | |
duke@435 | 119 | |
duke@435 | 120 | int Bytecode_invoke::index() const { |
duke@435 | 121 | return Bytes::get_Java_u2(bcp() + 1); |
duke@435 | 122 | } |
duke@435 | 123 | |
duke@435 | 124 | |
duke@435 | 125 | // Implementation of Bytecode_static |
duke@435 | 126 | |
duke@435 | 127 | void Bytecode_static::verify() const { |
duke@435 | 128 | assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic |
duke@435 | 129 | || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static"); |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | |
duke@435 | 133 | BasicType Bytecode_static::result_type(methodOop method) const { |
duke@435 | 134 | int index = java_hwrd_at(1); |
duke@435 | 135 | constantPoolOop constants = method->constants(); |
duke@435 | 136 | symbolOop field_type = constants->signature_ref_at(index); |
duke@435 | 137 | BasicType basic_type = FieldType::basic_type(field_type); |
duke@435 | 138 | return basic_type; |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | |
duke@435 | 142 | // Implementation of Bytecode_field |
duke@435 | 143 | |
duke@435 | 144 | void Bytecode_field::verify() const { |
duke@435 | 145 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 146 | assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic || |
duke@435 | 147 | stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field"); |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | |
duke@435 | 151 | bool Bytecode_field::is_static() const { |
duke@435 | 152 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 153 | return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic; |
duke@435 | 154 | } |
duke@435 | 155 | |
duke@435 | 156 | |
duke@435 | 157 | int Bytecode_field::index() const { |
duke@435 | 158 | return java_hwrd_at(1); |
duke@435 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | |
duke@435 | 162 | // Implementation of Bytecodes loac constant |
duke@435 | 163 | |
duke@435 | 164 | int Bytecode_loadconstant::index() const { |
duke@435 | 165 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 166 | return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1); |
duke@435 | 167 | } |
duke@435 | 168 | |
duke@435 | 169 | //------------------------------------------------------------------------------ |
duke@435 | 170 | // Non-product code |
duke@435 | 171 | |
duke@435 | 172 | #ifndef PRODUCT |
duke@435 | 173 | |
duke@435 | 174 | void Bytecode_lookupswitch::verify() const { |
duke@435 | 175 | switch (Bytecodes::java_code(code())) { |
duke@435 | 176 | case Bytecodes::_lookupswitch: |
duke@435 | 177 | { int i = number_of_pairs() - 1; |
duke@435 | 178 | while (i-- > 0) { |
duke@435 | 179 | assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries"); |
duke@435 | 180 | } |
duke@435 | 181 | } |
duke@435 | 182 | break; |
duke@435 | 183 | default: |
duke@435 | 184 | fatal("not a lookupswitch bytecode"); |
duke@435 | 185 | } |
duke@435 | 186 | } |
duke@435 | 187 | |
duke@435 | 188 | void Bytecode_tableswitch::verify() const { |
duke@435 | 189 | switch (Bytecodes::java_code(code())) { |
duke@435 | 190 | case Bytecodes::_tableswitch: |
duke@435 | 191 | { int lo = low_key(); |
duke@435 | 192 | int hi = high_key(); |
duke@435 | 193 | assert (hi >= lo, "incorrect hi/lo values in tableswitch"); |
duke@435 | 194 | int i = hi - lo - 1 ; |
duke@435 | 195 | while (i-- > 0) { |
duke@435 | 196 | // no special check needed |
duke@435 | 197 | } |
duke@435 | 198 | } |
duke@435 | 199 | break; |
duke@435 | 200 | default: |
duke@435 | 201 | fatal("not a tableswitch bytecode"); |
duke@435 | 202 | } |
duke@435 | 203 | } |
duke@435 | 204 | |
duke@435 | 205 | #endif |