1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/interpreter/bytecode.cpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,205 @@ 1.4 +/* 1.5 + * Copyright 1997-2002 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#include "incls/_precompiled.incl" 1.29 +#include "incls/_bytecode.cpp.incl" 1.30 + 1.31 +// Implementation of Bytecode 1.32 +// Should eventually get rid of these functions and use ThisRelativeObj methods instead 1.33 + 1.34 +void Bytecode::set_code(Bytecodes::Code code) { 1.35 + Bytecodes::check(code); 1.36 + *addr_at(0) = u_char(code); 1.37 +} 1.38 + 1.39 + 1.40 +void Bytecode::set_fast_index(int i) { 1.41 + assert(0 <= i && i < 0x10000, "illegal index value"); 1.42 + Bytes::put_native_u2(addr_at(1), (jushort)i); 1.43 +} 1.44 + 1.45 + 1.46 +bool Bytecode::check_must_rewrite() const { 1.47 + assert(Bytecodes::can_rewrite(code()), "post-check only"); 1.48 + 1.49 + // Some codes are conditionally rewriting. Look closely at them. 1.50 + switch (code()) { 1.51 + case Bytecodes::_aload_0: 1.52 + // Even if RewriteFrequentPairs is turned on, 1.53 + // the _aload_0 code might delay its rewrite until 1.54 + // a following _getfield rewrites itself. 1.55 + return false; 1.56 + 1.57 + case Bytecodes::_lookupswitch: 1.58 + return false; // the rewrite is not done by the interpreter 1.59 + 1.60 + case Bytecodes::_new: 1.61 + // (Could actually look at the class here, but the profit would be small.) 1.62 + return false; // the rewrite is not always done 1.63 + } 1.64 + 1.65 + // No other special cases. 1.66 + return true; 1.67 +} 1.68 + 1.69 + 1.70 + 1.71 +// Implementation of Bytecode_tableupswitch 1.72 + 1.73 +int Bytecode_tableswitch::dest_offset_at(int i) const { 1.74 + address x = aligned_addr_at(1); 1.75 + int x2 = aligned_offset(1 + (3 + i)*jintSize); 1.76 + int val = java_signed_word_at(x2); 1.77 + return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize)); 1.78 +} 1.79 + 1.80 + 1.81 +// Implementation of Bytecode_invoke 1.82 + 1.83 +void Bytecode_invoke::verify() const { 1.84 + Bytecodes::Code bc = adjusted_invoke_code(); 1.85 + assert(is_valid(), "check invoke"); 1.86 +} 1.87 + 1.88 + 1.89 +symbolOop Bytecode_invoke::signature() const { 1.90 + constantPoolOop constants = method()->constants(); 1.91 + return constants->signature_ref_at(index()); 1.92 +} 1.93 + 1.94 + 1.95 +symbolOop Bytecode_invoke::name() const { 1.96 + constantPoolOop constants = method()->constants(); 1.97 + return constants->name_ref_at(index()); 1.98 +} 1.99 + 1.100 + 1.101 +BasicType Bytecode_invoke::result_type(Thread *thread) const { 1.102 + symbolHandle sh(thread, signature()); 1.103 + ResultTypeFinder rts(sh); 1.104 + rts.iterate(); 1.105 + return rts.type(); 1.106 +} 1.107 + 1.108 + 1.109 +methodHandle Bytecode_invoke::static_target(TRAPS) { 1.110 + methodHandle m; 1.111 + KlassHandle resolved_klass; 1.112 + constantPoolHandle constants(THREAD, _method->constants()); 1.113 + 1.114 + if (adjusted_invoke_code() != Bytecodes::_invokeinterface) { 1.115 + LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); 1.116 + } else { 1.117 + LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); 1.118 + } 1.119 + return m; 1.120 +} 1.121 + 1.122 + 1.123 +int Bytecode_invoke::index() const { 1.124 + return Bytes::get_Java_u2(bcp() + 1); 1.125 +} 1.126 + 1.127 + 1.128 +// Implementation of Bytecode_static 1.129 + 1.130 +void Bytecode_static::verify() const { 1.131 + assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic 1.132 + || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static"); 1.133 +} 1.134 + 1.135 + 1.136 +BasicType Bytecode_static::result_type(methodOop method) const { 1.137 + int index = java_hwrd_at(1); 1.138 + constantPoolOop constants = method->constants(); 1.139 + symbolOop field_type = constants->signature_ref_at(index); 1.140 + BasicType basic_type = FieldType::basic_type(field_type); 1.141 + return basic_type; 1.142 +} 1.143 + 1.144 + 1.145 +// Implementation of Bytecode_field 1.146 + 1.147 +void Bytecode_field::verify() const { 1.148 + Bytecodes::Code stdc = Bytecodes::java_code(code()); 1.149 + assert(stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic || 1.150 + stdc == Bytecodes::_putfield || stdc == Bytecodes::_getfield, "check field"); 1.151 +} 1.152 + 1.153 + 1.154 +bool Bytecode_field::is_static() const { 1.155 + Bytecodes::Code stdc = Bytecodes::java_code(code()); 1.156 + return stdc == Bytecodes::_putstatic || stdc == Bytecodes::_getstatic; 1.157 +} 1.158 + 1.159 + 1.160 +int Bytecode_field::index() const { 1.161 + return java_hwrd_at(1); 1.162 +} 1.163 + 1.164 + 1.165 +// Implementation of Bytecodes loac constant 1.166 + 1.167 +int Bytecode_loadconstant::index() const { 1.168 + Bytecodes::Code stdc = Bytecodes::java_code(code()); 1.169 + return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1); 1.170 +} 1.171 + 1.172 +//------------------------------------------------------------------------------ 1.173 +// Non-product code 1.174 + 1.175 +#ifndef PRODUCT 1.176 + 1.177 +void Bytecode_lookupswitch::verify() const { 1.178 + switch (Bytecodes::java_code(code())) { 1.179 + case Bytecodes::_lookupswitch: 1.180 + { int i = number_of_pairs() - 1; 1.181 + while (i-- > 0) { 1.182 + assert(pair_at(i)->match() < pair_at(i+1)->match(), "unsorted table entries"); 1.183 + } 1.184 + } 1.185 + break; 1.186 + default: 1.187 + fatal("not a lookupswitch bytecode"); 1.188 + } 1.189 +} 1.190 + 1.191 +void Bytecode_tableswitch::verify() const { 1.192 + switch (Bytecodes::java_code(code())) { 1.193 + case Bytecodes::_tableswitch: 1.194 + { int lo = low_key(); 1.195 + int hi = high_key(); 1.196 + assert (hi >= lo, "incorrect hi/lo values in tableswitch"); 1.197 + int i = hi - lo - 1 ; 1.198 + while (i-- > 0) { 1.199 + // no special check needed 1.200 + } 1.201 + } 1.202 + break; 1.203 + default: 1.204 + fatal("not a tableswitch bytecode"); 1.205 + } 1.206 +} 1.207 + 1.208 +#endif