src/share/vm/runtime/rframe.cpp

Tue, 18 Mar 2014 19:07:22 +0100

author
pliden
date
Tue, 18 Mar 2014 19:07:22 +0100
changeset 6413
595c0f60d50d
parent 2708
1d1603768966
child 6876
710a3c8b516e
permissions
-rw-r--r--

8029075: String deduplication in G1
Summary: Implementation of JEP 192, http://openjdk.java.net/jeps/192
Reviewed-by: brutisso, tschatzl, coleenp

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

mercurial