Mon, 04 Jan 2010 18:38:08 +0100
6893081: method handle & invokedynamic code needs additional cleanup (post 6815692, 6858164)
Summary: During the work for 6829187 we have fixed a number of basic bugs which are logically grouped with 6815692 and 6858164 but which must be reviewed and pushed separately.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
xdono@1279 | 2 | * Copyright 1997-2009 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 | bool Bytecode::check_must_rewrite() const { |
duke@435 | 38 | assert(Bytecodes::can_rewrite(code()), "post-check only"); |
duke@435 | 39 | |
duke@435 | 40 | // Some codes are conditionally rewriting. Look closely at them. |
duke@435 | 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 | |
duke@435 | 61 | |
duke@435 | 62 | // Implementation of Bytecode_tableupswitch |
duke@435 | 63 | |
duke@435 | 64 | int Bytecode_tableswitch::dest_offset_at(int i) const { |
duke@435 | 65 | address x = aligned_addr_at(1); |
duke@435 | 66 | int x2 = aligned_offset(1 + (3 + i)*jintSize); |
duke@435 | 67 | int val = java_signed_word_at(x2); |
duke@435 | 68 | return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize)); |
duke@435 | 69 | } |
duke@435 | 70 | |
duke@435 | 71 | |
duke@435 | 72 | // Implementation of Bytecode_invoke |
duke@435 | 73 | |
duke@435 | 74 | void Bytecode_invoke::verify() const { |
duke@435 | 75 | Bytecodes::Code bc = adjusted_invoke_code(); |
duke@435 | 76 | assert(is_valid(), "check invoke"); |
duke@435 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | |
duke@435 | 80 | symbolOop Bytecode_invoke::signature() const { |
duke@435 | 81 | constantPoolOop constants = method()->constants(); |
duke@435 | 82 | return constants->signature_ref_at(index()); |
duke@435 | 83 | } |
duke@435 | 84 | |
duke@435 | 85 | |
duke@435 | 86 | symbolOop Bytecode_invoke::name() const { |
duke@435 | 87 | constantPoolOop constants = method()->constants(); |
duke@435 | 88 | return constants->name_ref_at(index()); |
duke@435 | 89 | } |
duke@435 | 90 | |
duke@435 | 91 | |
duke@435 | 92 | BasicType Bytecode_invoke::result_type(Thread *thread) const { |
duke@435 | 93 | symbolHandle sh(thread, signature()); |
duke@435 | 94 | ResultTypeFinder rts(sh); |
duke@435 | 95 | rts.iterate(); |
duke@435 | 96 | return rts.type(); |
duke@435 | 97 | } |
duke@435 | 98 | |
duke@435 | 99 | |
duke@435 | 100 | methodHandle Bytecode_invoke::static_target(TRAPS) { |
duke@435 | 101 | methodHandle m; |
duke@435 | 102 | KlassHandle resolved_klass; |
duke@435 | 103 | constantPoolHandle constants(THREAD, _method->constants()); |
duke@435 | 104 | |
twisti@1570 | 105 | if (adjusted_invoke_code() == Bytecodes::_invokedynamic) { |
twisti@1570 | 106 | LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
twisti@1570 | 107 | } else if (adjusted_invoke_code() != Bytecodes::_invokeinterface) { |
duke@435 | 108 | LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 109 | } else { |
duke@435 | 110 | LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 111 | } |
duke@435 | 112 | return m; |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | |
duke@435 | 116 | int Bytecode_invoke::index() const { |
jrose@1161 | 117 | // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
jrose@1161 | 118 | // at the same time it allocates per-call-site CP cache entries. |
jrose@1161 | 119 | if (has_giant_index()) |
jrose@1161 | 120 | return Bytes::get_native_u4(bcp() + 1); |
jrose@1161 | 121 | else |
jrose@1161 | 122 | return Bytes::get_Java_u2(bcp() + 1); |
duke@435 | 123 | } |
duke@435 | 124 | |
duke@435 | 125 | |
duke@435 | 126 | // Implementation of Bytecode_static |
duke@435 | 127 | |
duke@435 | 128 | void Bytecode_static::verify() const { |
duke@435 | 129 | assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic |
duke@435 | 130 | || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static"); |
duke@435 | 131 | } |
duke@435 | 132 | |
duke@435 | 133 | |
duke@435 | 134 | BasicType Bytecode_static::result_type(methodOop method) const { |
duke@435 | 135 | int index = java_hwrd_at(1); |
duke@435 | 136 | constantPoolOop constants = method->constants(); |
duke@435 | 137 | symbolOop field_type = constants->signature_ref_at(index); |
duke@435 | 138 | BasicType basic_type = FieldType::basic_type(field_type); |
duke@435 | 139 | return basic_type; |
duke@435 | 140 | } |
duke@435 | 141 | |
duke@435 | 142 | |
duke@435 | 143 | // Implementation of Bytecode_field |
duke@435 | 144 | |
duke@435 | 145 | void Bytecode_field::verify() const { |
duke@435 | 146 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 147 | assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic || |
duke@435 | 148 | stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field"); |
duke@435 | 149 | } |
duke@435 | 150 | |
duke@435 | 151 | |
duke@435 | 152 | bool Bytecode_field::is_static() const { |
duke@435 | 153 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 154 | return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic; |
duke@435 | 155 | } |
duke@435 | 156 | |
duke@435 | 157 | |
duke@435 | 158 | int Bytecode_field::index() const { |
duke@435 | 159 | return java_hwrd_at(1); |
duke@435 | 160 | } |
duke@435 | 161 | |
duke@435 | 162 | |
duke@435 | 163 | // Implementation of Bytecodes loac constant |
duke@435 | 164 | |
duke@435 | 165 | int Bytecode_loadconstant::index() const { |
duke@435 | 166 | Bytecodes::Code stdc = Bytecodes::java_code(code()); |
duke@435 | 167 | return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1); |
duke@435 | 168 | } |
duke@435 | 169 | |
duke@435 | 170 | //------------------------------------------------------------------------------ |
duke@435 | 171 | // Non-product code |
duke@435 | 172 | |
duke@435 | 173 | #ifndef PRODUCT |
duke@435 | 174 | |
duke@435 | 175 | void Bytecode_lookupswitch::verify() const { |
duke@435 | 176 | switch (Bytecodes::java_code(code())) { |
duke@435 | 177 | case Bytecodes::_lookupswitch: |
duke@435 | 178 | { int i = number_of_pairs() - 1; |
duke@435 | 179 | while (i-- > 0) { |
duke@435 | 180 | assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries"); |
duke@435 | 181 | } |
duke@435 | 182 | } |
duke@435 | 183 | break; |
duke@435 | 184 | default: |
duke@435 | 185 | fatal("not a lookupswitch bytecode"); |
duke@435 | 186 | } |
duke@435 | 187 | } |
duke@435 | 188 | |
duke@435 | 189 | void Bytecode_tableswitch::verify() const { |
duke@435 | 190 | switch (Bytecodes::java_code(code())) { |
duke@435 | 191 | case Bytecodes::_tableswitch: |
duke@435 | 192 | { int lo = low_key(); |
duke@435 | 193 | int hi = high_key(); |
duke@435 | 194 | assert (hi >= lo, "incorrect hi/lo values in tableswitch"); |
duke@435 | 195 | int i = hi - lo - 1 ; |
duke@435 | 196 | while (i-- > 0) { |
duke@435 | 197 | // no special check needed |
duke@435 | 198 | } |
duke@435 | 199 | } |
duke@435 | 200 | break; |
duke@435 | 201 | default: |
duke@435 | 202 | fatal("not a tableswitch bytecode"); |
duke@435 | 203 | } |
duke@435 | 204 | } |
duke@435 | 205 | |
duke@435 | 206 | #endif |