1.1 --- a/src/share/vm/interpreter/bytecode.cpp Tue Jun 01 11:48:33 2010 -0700 1.2 +++ b/src/share/vm/interpreter/bytecode.cpp Wed Jun 02 22:45:42 2010 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -26,19 +26,12 @@ 1.11 #include "incls/_bytecode.cpp.incl" 1.12 1.13 // Implementation of Bytecode 1.14 -// Should eventually get rid of these functions and use ThisRelativeObj methods instead 1.15 1.16 -void Bytecode::set_code(Bytecodes::Code code) { 1.17 - Bytecodes::check(code); 1.18 - *addr_at(0) = u_char(code); 1.19 -} 1.20 - 1.21 - 1.22 -bool Bytecode::check_must_rewrite() const { 1.23 - assert(Bytecodes::can_rewrite(code()), "post-check only"); 1.24 +bool Bytecode::check_must_rewrite(Bytecodes::Code code) const { 1.25 + assert(Bytecodes::can_rewrite(code), "post-check only"); 1.26 1.27 // Some codes are conditionally rewriting. Look closely at them. 1.28 - switch (code()) { 1.29 + switch (code) { 1.30 case Bytecodes::_aload_0: 1.31 // Even if RewriteFrequentPairs is turned on, 1.32 // the _aload_0 code might delay its rewrite until 1.33 @@ -58,14 +51,85 @@ 1.34 } 1.35 1.36 1.37 +#ifdef ASSERT 1.38 + 1.39 +void Bytecode::assert_same_format_as(Bytecodes::Code testbc, bool is_wide) const { 1.40 + Bytecodes::Code thisbc = Bytecodes::cast(byte_at(0)); 1.41 + if (thisbc == Bytecodes::_breakpoint) return; // let the assertion fail silently 1.42 + if (is_wide) { 1.43 + assert(thisbc == Bytecodes::_wide, "expected a wide instruction"); 1.44 + thisbc = Bytecodes::cast(byte_at(1)); 1.45 + if (thisbc == Bytecodes::_breakpoint) return; 1.46 + } 1.47 + int thisflags = Bytecodes::flags(testbc, is_wide) & Bytecodes::_all_fmt_bits; 1.48 + int testflags = Bytecodes::flags(thisbc, is_wide) & Bytecodes::_all_fmt_bits; 1.49 + if (thisflags != testflags) 1.50 + tty->print_cr("assert_same_format_as(%d) failed on bc=%d%s; %d != %d", 1.51 + (int)testbc, (int)thisbc, (is_wide?"/wide":""), testflags, thisflags); 1.52 + assert(thisflags == testflags, "expected format"); 1.53 +} 1.54 + 1.55 +void Bytecode::assert_index_size(int size, Bytecodes::Code bc, bool is_wide) { 1.56 + int have_fmt = (Bytecodes::flags(bc, is_wide) 1.57 + & (Bytecodes::_fmt_has_u2 | Bytecodes::_fmt_has_u4 | 1.58 + Bytecodes::_fmt_not_simple | 1.59 + // Not an offset field: 1.60 + Bytecodes::_fmt_has_o)); 1.61 + int need_fmt = -1; 1.62 + switch (size) { 1.63 + case 1: need_fmt = 0; break; 1.64 + case 2: need_fmt = Bytecodes::_fmt_has_u2; break; 1.65 + case 4: need_fmt = Bytecodes::_fmt_has_u4; break; 1.66 + } 1.67 + if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; 1.68 + if (have_fmt != need_fmt) { 1.69 + tty->print_cr("assert_index_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); 1.70 + assert(have_fmt == need_fmt, "assert_index_size"); 1.71 + } 1.72 +} 1.73 + 1.74 +void Bytecode::assert_offset_size(int size, Bytecodes::Code bc, bool is_wide) { 1.75 + int have_fmt = Bytecodes::flags(bc, is_wide) & Bytecodes::_all_fmt_bits; 1.76 + int need_fmt = -1; 1.77 + switch (size) { 1.78 + case 2: need_fmt = Bytecodes::_fmt_bo2; break; 1.79 + case 4: need_fmt = Bytecodes::_fmt_bo4; break; 1.80 + } 1.81 + if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; 1.82 + if (have_fmt != need_fmt) { 1.83 + tty->print_cr("assert_offset_size %d: bc=%d%s %d != %d", size, bc, (is_wide?"/wide":""), have_fmt, need_fmt); 1.84 + assert(have_fmt == need_fmt, "assert_offset_size"); 1.85 + } 1.86 +} 1.87 + 1.88 +void Bytecode::assert_constant_size(int size, int where, Bytecodes::Code bc, bool is_wide) { 1.89 + int have_fmt = Bytecodes::flags(bc, is_wide) & (Bytecodes::_all_fmt_bits 1.90 + // Ignore any 'i' field (for iinc): 1.91 + & ~Bytecodes::_fmt_has_i); 1.92 + int need_fmt = -1; 1.93 + switch (size) { 1.94 + case 1: need_fmt = Bytecodes::_fmt_bc; break; 1.95 + case 2: need_fmt = Bytecodes::_fmt_bc | Bytecodes::_fmt_has_u2; break; 1.96 + } 1.97 + if (is_wide) need_fmt |= Bytecodes::_fmt_not_simple; 1.98 + int length = is_wide ? Bytecodes::wide_length_for(bc) : Bytecodes::length_for(bc); 1.99 + if (have_fmt != need_fmt || where + size != length) { 1.100 + tty->print_cr("assert_constant_size %d @%d: bc=%d%s %d != %d", size, where, bc, (is_wide?"/wide":""), have_fmt, need_fmt); 1.101 + } 1.102 + assert(have_fmt == need_fmt, "assert_constant_size"); 1.103 + assert(where + size == length, "assert_constant_size oob"); 1.104 +} 1.105 + 1.106 +void Bytecode::assert_native_index(Bytecodes::Code bc, bool is_wide) { 1.107 + assert((Bytecodes::flags(bc, is_wide) & Bytecodes::_fmt_has_nbo) != 0, "native index"); 1.108 +} 1.109 + 1.110 +#endif //ASSERT 1.111 1.112 // Implementation of Bytecode_tableupswitch 1.113 1.114 int Bytecode_tableswitch::dest_offset_at(int i) const { 1.115 - address x = aligned_addr_at(1); 1.116 - int x2 = aligned_offset(1 + (3 + i)*jintSize); 1.117 - int val = java_signed_word_at(x2); 1.118 - return java_signed_word_at(aligned_offset(1 + (3 + i)*jintSize)); 1.119 + return get_Java_u4_at(aligned_offset(1 + (3 + i)*jintSize)); 1.120 } 1.121 1.122 1.123 @@ -74,6 +138,7 @@ 1.124 void Bytecode_invoke::verify() const { 1.125 Bytecodes::Code bc = adjusted_invoke_code(); 1.126 assert(is_valid(), "check invoke"); 1.127 + assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter"); 1.128 } 1.129 1.130 1.131 @@ -116,27 +181,12 @@ 1.132 int Bytecode_invoke::index() const { 1.133 // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, 1.134 // at the same time it allocates per-call-site CP cache entries. 1.135 - if (has_giant_index()) 1.136 - return Bytes::get_native_u4(bcp() + 1); 1.137 + Bytecodes::Code stdc = Bytecodes::java_code(code()); 1.138 + Bytecode* invoke = Bytecode_at(bcp()); 1.139 + if (invoke->has_index_u4(stdc)) 1.140 + return invoke->get_index_u4(stdc); 1.141 else 1.142 - return Bytes::get_Java_u2(bcp() + 1); 1.143 -} 1.144 - 1.145 - 1.146 -// Implementation of Bytecode_static 1.147 - 1.148 -void Bytecode_static::verify() const { 1.149 - assert(Bytecodes::java_code(code()) == Bytecodes::_putstatic 1.150 - || Bytecodes::java_code(code()) == Bytecodes::_getstatic, "check static"); 1.151 -} 1.152 - 1.153 - 1.154 -BasicType Bytecode_static::result_type(methodOop method) const { 1.155 - int index = java_hwrd_at(1); 1.156 - constantPoolOop constants = method->constants(); 1.157 - symbolOop field_type = constants->signature_ref_at(index); 1.158 - BasicType basic_type = FieldType::basic_type(field_type); 1.159 - return basic_type; 1.160 + return invoke->get_index_u2_cpcache(stdc); 1.161 } 1.162 1.163 1.164 @@ -156,7 +206,8 @@ 1.165 1.166 1.167 int Bytecode_field::index() const { 1.168 - return java_hwrd_at(1); 1.169 + Bytecode* invoke = Bytecode_at(bcp()); 1.170 + return invoke->get_index_u2_cpcache(Bytecodes::_getfield); 1.171 } 1.172 1.173 1.174 @@ -164,7 +215,14 @@ 1.175 1.176 int Bytecode_loadconstant::index() const { 1.177 Bytecodes::Code stdc = Bytecodes::java_code(code()); 1.178 - return stdc == Bytecodes::_ldc ? java_byte_at(1) : java_hwrd_at(1); 1.179 + if (stdc != Bytecodes::_wide) { 1.180 + if (Bytecodes::java_code(stdc) == Bytecodes::_ldc) 1.181 + return get_index_u1(stdc); 1.182 + else 1.183 + return get_index_u2(stdc, false); 1.184 + } 1.185 + stdc = Bytecodes::code_at(addr_at(1)); 1.186 + return get_index_u2(stdc, true); 1.187 } 1.188 1.189 //------------------------------------------------------------------------------