Mon, 23 Jun 2008 14:11:12 -0700
6708714: Optimize long LShift on 32-bits x86
Summary: For small (1-3 bits) left long shifts in 32-bits VM use sets of add+addc instructions instead of shld+shl on new AMD cpus.
Reviewed-by: never
Contributed-by: shrinivas.joshi@amd.com
duke@435 | 1 | /* |
duke@435 | 2 | * Copyright 1997-2007 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 | |
duke@435 | 27 | #include "incls/_rframe.cpp.incl" |
duke@435 | 28 | |
duke@435 | 29 | static RFrame*const noCaller = (RFrame*) 0x1; // no caller (i.e., initial frame) |
duke@435 | 30 | static RFrame*const noCallerYet = (RFrame*) 0x0; // caller not yet computed |
duke@435 | 31 | |
duke@435 | 32 | RFrame::RFrame(frame fr, JavaThread* thread, RFrame*const callee) : |
duke@435 | 33 | _fr(fr), _thread(thread), _callee(callee), _num(callee ? callee->num() + 1 : 0) { |
duke@435 | 34 | _caller = (RFrame*)noCallerYet; |
duke@435 | 35 | _invocations = 0; |
duke@435 | 36 | _distance = 0; |
duke@435 | 37 | } |
duke@435 | 38 | |
duke@435 | 39 | void RFrame::set_distance(int d) { |
duke@435 | 40 | assert(is_compiled() || d >= 0, "should be positive"); |
duke@435 | 41 | _distance = d; |
duke@435 | 42 | } |
duke@435 | 43 | |
duke@435 | 44 | InterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, RFrame*const callee) |
duke@435 | 45 | : RFrame(fr, thread, callee) { |
duke@435 | 46 | RegisterMap map(thread, false); |
duke@435 | 47 | _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread)); |
duke@435 | 48 | _method = methodHandle(thread, _vf->method()); |
duke@435 | 49 | assert( _vf->is_interpreted_frame(), "must be interpreted"); |
duke@435 | 50 | init(); |
duke@435 | 51 | } |
duke@435 | 52 | |
duke@435 | 53 | InterpretedRFrame::InterpretedRFrame(frame fr, JavaThread* thread, methodHandle m) |
duke@435 | 54 | : RFrame(fr, thread, NULL) { |
duke@435 | 55 | RegisterMap map(thread, false); |
duke@435 | 56 | _vf = javaVFrame::cast(vframe::new_vframe(&_fr, &map, thread)); |
duke@435 | 57 | _method = m; |
duke@435 | 58 | |
duke@435 | 59 | assert( _vf->is_interpreted_frame(), "must be interpreted"); |
duke@435 | 60 | init(); |
duke@435 | 61 | } |
duke@435 | 62 | |
duke@435 | 63 | CompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread, RFrame*const callee) |
duke@435 | 64 | : RFrame(fr, thread, callee) { |
duke@435 | 65 | init(); |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | CompiledRFrame::CompiledRFrame(frame fr, JavaThread* thread) |
duke@435 | 69 | : RFrame(fr, thread, NULL) { |
duke@435 | 70 | init(); |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | DeoptimizedRFrame::DeoptimizedRFrame(frame fr, JavaThread* thread, RFrame*const callee) |
duke@435 | 74 | : InterpretedRFrame(fr, thread, callee) {} |
duke@435 | 75 | |
duke@435 | 76 | RFrame* RFrame::new_RFrame(frame fr, JavaThread* thread, RFrame*const callee) { |
duke@435 | 77 | RFrame* rf; |
duke@435 | 78 | int dist = callee ? callee->distance() : -1; |
duke@435 | 79 | if (fr.is_interpreted_frame()) { |
duke@435 | 80 | rf = new InterpretedRFrame(fr, thread, callee); |
duke@435 | 81 | dist++; |
duke@435 | 82 | } else if (fr.is_compiled_frame()) { |
duke@435 | 83 | // Even deopted frames look compiled because the deopt |
duke@435 | 84 | // is invisible until it happens. |
duke@435 | 85 | rf = new CompiledRFrame(fr, thread, callee); |
duke@435 | 86 | } else { |
duke@435 | 87 | assert(false, "Unhandled frame type"); |
duke@435 | 88 | } |
duke@435 | 89 | rf->set_distance(dist); |
duke@435 | 90 | rf->init(); |
duke@435 | 91 | return rf; |
duke@435 | 92 | } |
duke@435 | 93 | |
duke@435 | 94 | RFrame* RFrame::caller() { |
duke@435 | 95 | if (_caller != noCallerYet) return (_caller == noCaller) ? NULL : _caller; // already computed caller |
duke@435 | 96 | |
duke@435 | 97 | // caller not yet computed; do it now |
duke@435 | 98 | if (_fr.is_first_java_frame()) { |
duke@435 | 99 | _caller = (RFrame*)noCaller; |
duke@435 | 100 | return NULL; |
duke@435 | 101 | } |
duke@435 | 102 | |
duke@435 | 103 | RegisterMap map(_thread, false); |
duke@435 | 104 | frame sender = _fr.real_sender(&map); |
duke@435 | 105 | if (sender.is_java_frame()) { |
duke@435 | 106 | _caller = new_RFrame(sender, thread(), this); |
duke@435 | 107 | return _caller; |
duke@435 | 108 | } |
duke@435 | 109 | |
duke@435 | 110 | // Real caller is not java related |
duke@435 | 111 | _caller = (RFrame*)noCaller; |
duke@435 | 112 | return NULL; |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | int InterpretedRFrame::cost() const { |
duke@435 | 116 | return _method->code_size(); // fix this |
duke@435 | 117 | //return _method->estimated_inline_cost(_receiverKlass); |
duke@435 | 118 | } |
duke@435 | 119 | |
duke@435 | 120 | int CompiledRFrame::cost() const { |
duke@435 | 121 | nmethod* nm = top_method()->code(); |
duke@435 | 122 | if (nm != NULL) { |
duke@435 | 123 | return nm->code_size(); |
duke@435 | 124 | } else { |
duke@435 | 125 | return top_method()->code_size(); |
duke@435 | 126 | } |
duke@435 | 127 | } |
duke@435 | 128 | |
duke@435 | 129 | void CompiledRFrame::init() { |
duke@435 | 130 | RegisterMap map(thread(), false); |
duke@435 | 131 | vframe* vf = vframe::new_vframe(&_fr, &map, thread()); |
duke@435 | 132 | assert(vf->is_compiled_frame(), "must be compiled"); |
duke@435 | 133 | _nm = compiledVFrame::cast(vf)->code(); |
duke@435 | 134 | vf = vf->top(); |
duke@435 | 135 | _vf = javaVFrame::cast(vf); |
duke@435 | 136 | _method = methodHandle(thread(), CodeCache::find_nmethod(_fr.pc())->method()); |
duke@435 | 137 | assert(_method(), "should have found a method"); |
duke@435 | 138 | #ifndef PRODUCT |
duke@435 | 139 | _invocations = _method->compiled_invocation_count(); |
duke@435 | 140 | #endif |
duke@435 | 141 | } |
duke@435 | 142 | |
duke@435 | 143 | void InterpretedRFrame::init() { |
duke@435 | 144 | _invocations = _method->invocation_count() + _method->backedge_count(); |
duke@435 | 145 | } |
duke@435 | 146 | |
duke@435 | 147 | void RFrame::print(const char* kind) { |
duke@435 | 148 | #ifndef PRODUCT |
duke@435 | 149 | #ifdef COMPILER2 |
duke@435 | 150 | int cnt = top_method()->interpreter_invocation_count(); |
duke@435 | 151 | #else |
duke@435 | 152 | int cnt = top_method()->invocation_count(); |
duke@435 | 153 | #endif |
duke@435 | 154 | tty->print("%3d %s ", _num, is_interpreted() ? "I" : "C"); |
duke@435 | 155 | top_method()->print_short_name(tty); |
duke@435 | 156 | tty->print_cr(": inv=%5d(%d) cst=%4d", _invocations, cnt, cost()); |
duke@435 | 157 | #endif |
duke@435 | 158 | } |
duke@435 | 159 | |
duke@435 | 160 | void CompiledRFrame::print() { |
duke@435 | 161 | RFrame::print("comp"); |
duke@435 | 162 | } |
duke@435 | 163 | |
duke@435 | 164 | void InterpretedRFrame::print() { |
duke@435 | 165 | RFrame::print("int."); |
duke@435 | 166 | } |
duke@435 | 167 | |
duke@435 | 168 | void DeoptimizedRFrame::print() { |
duke@435 | 169 | RFrame::print("deopt."); |
duke@435 | 170 | } |