Tue, 15 May 2012 10:10:23 +0200
7133857: exp() and pow() should use the x87 ISA on x86
Summary: use x87 instructions to implement exp() and pow() in interpreter/c1/c2.
Reviewed-by: kvn, never, twisti
duke@435 | 1 | /* |
never@2462 | 2 | * Copyright (c) 1997, 2011, 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" |
stefank@2314 | 28 | #include "oops/constantPoolOop.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"); |
jrose@1920 | 123 | assert(method()->constants()->cache() != NULL, "do not call this from verifier or rewriter"); |
duke@435 | 124 | } |
duke@435 | 125 | |
duke@435 | 126 | |
coleenp@2497 | 127 | Symbol* Bytecode_member_ref::signature() const { |
duke@435 | 128 | constantPoolOop constants = method()->constants(); |
duke@435 | 129 | return constants->signature_ref_at(index()); |
duke@435 | 130 | } |
duke@435 | 131 | |
duke@435 | 132 | |
coleenp@2497 | 133 | Symbol* Bytecode_member_ref::name() const { |
duke@435 | 134 | constantPoolOop constants = method()->constants(); |
duke@435 | 135 | return constants->name_ref_at(index()); |
duke@435 | 136 | } |
duke@435 | 137 | |
duke@435 | 138 | |
coleenp@2497 | 139 | BasicType Bytecode_member_ref::result_type() const { |
coleenp@2497 | 140 | ResultTypeFinder rts(signature()); |
duke@435 | 141 | rts.iterate(); |
duke@435 | 142 | return rts.type(); |
duke@435 | 143 | } |
duke@435 | 144 | |
duke@435 | 145 | |
duke@435 | 146 | methodHandle Bytecode_invoke::static_target(TRAPS) { |
duke@435 | 147 | methodHandle m; |
duke@435 | 148 | KlassHandle resolved_klass; |
duke@435 | 149 | constantPoolHandle constants(THREAD, _method->constants()); |
duke@435 | 150 | |
jrose@1957 | 151 | if (java_code() == Bytecodes::_invokedynamic) { |
twisti@1570 | 152 | LinkResolver::resolve_dynamic_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
jrose@1957 | 153 | } else if (java_code() != Bytecodes::_invokeinterface) { |
duke@435 | 154 | LinkResolver::resolve_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 155 | } else { |
duke@435 | 156 | LinkResolver::resolve_interface_method(m, resolved_klass, constants, index(), CHECK_(methodHandle())); |
duke@435 | 157 | } |
duke@435 | 158 | return m; |
duke@435 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | |
jrose@1957 | 162 | int Bytecode_member_ref::index() const { |
jrose@1161 | 163 | // Note: Rewriter::rewrite changes the Java_u2 of an invokedynamic to a native_u4, |
jrose@1161 | 164 | // at the same time it allocates per-call-site CP cache entries. |
jrose@1957 | 165 | Bytecodes::Code rawc = code(); |
never@2462 | 166 | if (has_index_u4(rawc)) |
never@2462 | 167 | return get_index_u4(rawc); |
jrose@1161 | 168 | else |
never@2462 | 169 | return get_index_u2_cpcache(rawc); |
duke@435 | 170 | } |
duke@435 | 171 | |
jrose@1957 | 172 | int Bytecode_member_ref::pool_index() const { |
jrose@1957 | 173 | int index = this->index(); |
jrose@1957 | 174 | DEBUG_ONLY({ |
never@2462 | 175 | if (!has_index_u4(code())) |
jrose@1957 | 176 | index -= constantPoolOopDesc::CPCACHE_INDEX_TAG; |
jrose@1957 | 177 | }); |
jrose@1957 | 178 | return _method->constants()->cache()->entry_at(index)->constant_pool_index(); |
jrose@1957 | 179 | } |
duke@435 | 180 | |
duke@435 | 181 | // Implementation of Bytecode_field |
duke@435 | 182 | |
duke@435 | 183 | void Bytecode_field::verify() const { |
jrose@1957 | 184 | assert(is_valid(), "check field"); |
duke@435 | 185 | } |
duke@435 | 186 | |
duke@435 | 187 | |
jrose@1957 | 188 | // Implementation of Bytecode_loadconstant |
jrose@1957 | 189 | |
jrose@1957 | 190 | int Bytecode_loadconstant::raw_index() const { |
never@2462 | 191 | Bytecodes::Code rawc = code(); |
jrose@1957 | 192 | assert(rawc != Bytecodes::_wide, "verifier prevents this"); |
jrose@1957 | 193 | if (Bytecodes::java_code(rawc) == Bytecodes::_ldc) |
never@2462 | 194 | return get_index_u1(rawc); |
jrose@1957 | 195 | else |
never@2462 | 196 | return get_index_u2(rawc, false); |
duke@435 | 197 | } |
duke@435 | 198 | |
jrose@1957 | 199 | int Bytecode_loadconstant::pool_index() const { |
jrose@1957 | 200 | int index = raw_index(); |
jrose@1957 | 201 | if (has_cache_index()) { |
jrose@1957 | 202 | return _method->constants()->cache()->entry_at(index)->constant_pool_index(); |
jrose@1957 | 203 | } |
jrose@1957 | 204 | return index; |
duke@435 | 205 | } |
duke@435 | 206 | |
jrose@1957 | 207 | BasicType Bytecode_loadconstant::result_type() const { |
jrose@1957 | 208 | int index = pool_index(); |
jrose@1957 | 209 | constantTag tag = _method->constants()->tag_at(index); |
jrose@1957 | 210 | return tag.basic_type(); |
jrose@1957 | 211 | } |
duke@435 | 212 | |
jrose@1957 | 213 | oop Bytecode_loadconstant::resolve_constant(TRAPS) const { |
jrose@1957 | 214 | assert(_method.not_null(), "must supply method to resolve constant"); |
jrose@1957 | 215 | int index = raw_index(); |
jrose@1957 | 216 | constantPoolOop constants = _method->constants(); |
jrose@1957 | 217 | if (has_cache_index()) { |
jrose@1957 | 218 | return constants->resolve_cached_constant_at(index, THREAD); |
jrose@1957 | 219 | } else { |
jrose@1957 | 220 | return constants->resolve_constant_at(index, THREAD); |
jrose@1929 | 221 | } |
duke@435 | 222 | } |
duke@435 | 223 | |
duke@435 | 224 | //------------------------------------------------------------------------------ |
duke@435 | 225 | // Non-product code |
duke@435 | 226 | |
duke@435 | 227 | #ifndef PRODUCT |
duke@435 | 228 | |
duke@435 | 229 | void Bytecode_lookupswitch::verify() const { |
duke@435 | 230 | switch (Bytecodes::java_code(code())) { |
duke@435 | 231 | case Bytecodes::_lookupswitch: |
duke@435 | 232 | { int i = number_of_pairs() - 1; |
duke@435 | 233 | while (i-- > 0) { |
never@2462 | 234 | assert(pair_at(i).match() < pair_at(i+1).match(), "unsorted table entries"); |
duke@435 | 235 | } |
duke@435 | 236 | } |
duke@435 | 237 | break; |
duke@435 | 238 | default: |
duke@435 | 239 | fatal("not a lookupswitch bytecode"); |
duke@435 | 240 | } |
duke@435 | 241 | } |
duke@435 | 242 | |
duke@435 | 243 | void Bytecode_tableswitch::verify() const { |
duke@435 | 244 | switch (Bytecodes::java_code(code())) { |
duke@435 | 245 | case Bytecodes::_tableswitch: |
duke@435 | 246 | { int lo = low_key(); |
duke@435 | 247 | int hi = high_key(); |
duke@435 | 248 | assert (hi >= lo, "incorrect hi/lo values in tableswitch"); |
duke@435 | 249 | int i = hi - lo - 1 ; |
duke@435 | 250 | while (i-- > 0) { |
duke@435 | 251 | // no special check needed |
duke@435 | 252 | } |
duke@435 | 253 | } |
duke@435 | 254 | break; |
duke@435 | 255 | default: |
duke@435 | 256 | fatal("not a tableswitch bytecode"); |
duke@435 | 257 | } |
duke@435 | 258 | } |
duke@435 | 259 | |
duke@435 | 260 | #endif |