comparison src/share/vm/oops/instanceKlass.cpp @ 1783:d5d065957597

6953144: Tiered compilation Summary: Infrastructure for tiered compilation support (interpreter + c1 + c2) for 32 and 64 bit. Simple tiered policy implementation. Reviewed-by: kvn, never, phh, twisti
author iveresov
date Fri, 03 Sep 2010 17:51:07 -0700
parents 2528b5bd749c
children 2d26b0046e0d f95d63e2154a
comparison
equal deleted inserted replaced
1782:f353275af40e 1783:d5d065957597
1 /* 1 /*
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
2198 // This is a short non-blocking critical region, so the no safepoint check is ok. 2198 // This is a short non-blocking critical region, so the no safepoint check is ok.
2199 OsrList_lock->lock_without_safepoint_check(); 2199 OsrList_lock->lock_without_safepoint_check();
2200 assert(n->is_osr_method(), "wrong kind of nmethod"); 2200 assert(n->is_osr_method(), "wrong kind of nmethod");
2201 n->set_osr_link(osr_nmethods_head()); 2201 n->set_osr_link(osr_nmethods_head());
2202 set_osr_nmethods_head(n); 2202 set_osr_nmethods_head(n);
2203 // Raise the highest osr level if necessary
2204 if (TieredCompilation) {
2205 methodOop m = n->method();
2206 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
2207 }
2203 // Remember to unlock again 2208 // Remember to unlock again
2204 OsrList_lock->unlock(); 2209 OsrList_lock->unlock();
2210
2211 // Get rid of the osr methods for the same bci that have lower levels.
2212 if (TieredCompilation) {
2213 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
2214 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
2215 if (inv != NULL && inv->is_in_use()) {
2216 inv->make_not_entrant();
2217 }
2218 }
2219 }
2205 } 2220 }
2206 2221
2207 2222
2208 void instanceKlass::remove_osr_nmethod(nmethod* n) { 2223 void instanceKlass::remove_osr_nmethod(nmethod* n) {
2209 // This is a short non-blocking critical region, so the no safepoint check is ok. 2224 // This is a short non-blocking critical region, so the no safepoint check is ok.
2210 OsrList_lock->lock_without_safepoint_check(); 2225 OsrList_lock->lock_without_safepoint_check();
2211 assert(n->is_osr_method(), "wrong kind of nmethod"); 2226 assert(n->is_osr_method(), "wrong kind of nmethod");
2212 nmethod* last = NULL; 2227 nmethod* last = NULL;
2213 nmethod* cur = osr_nmethods_head(); 2228 nmethod* cur = osr_nmethods_head();
2229 int max_level = CompLevel_none; // Find the max comp level excluding n
2230 methodOop m = n->method();
2214 // Search for match 2231 // Search for match
2215 while(cur != NULL && cur != n) { 2232 while(cur != NULL && cur != n) {
2233 if (TieredCompilation) {
2234 // Find max level before n
2235 max_level = MAX2(max_level, cur->comp_level());
2236 }
2216 last = cur; 2237 last = cur;
2217 cur = cur->osr_link(); 2238 cur = cur->osr_link();
2218 } 2239 }
2240 nmethod* next = NULL;
2219 if (cur == n) { 2241 if (cur == n) {
2242 next = cur->osr_link();
2220 if (last == NULL) { 2243 if (last == NULL) {
2221 // Remove first element 2244 // Remove first element
2222 set_osr_nmethods_head(osr_nmethods_head()->osr_link()); 2245 set_osr_nmethods_head(next);
2223 } else { 2246 } else {
2224 last->set_osr_link(cur->osr_link()); 2247 last->set_osr_link(next);
2225 } 2248 }
2226 } 2249 }
2227 n->set_osr_link(NULL); 2250 n->set_osr_link(NULL);
2251 if (TieredCompilation) {
2252 cur = next;
2253 while (cur != NULL) {
2254 // Find max level after n
2255 max_level = MAX2(max_level, cur->comp_level());
2256 cur = cur->osr_link();
2257 }
2258 m->set_highest_osr_comp_level(max_level);
2259 }
2228 // Remember to unlock again 2260 // Remember to unlock again
2229 OsrList_lock->unlock(); 2261 OsrList_lock->unlock();
2230 } 2262 }
2231 2263
2232 nmethod* instanceKlass::lookup_osr_nmethod(const methodOop m, int bci) const { 2264 nmethod* instanceKlass::lookup_osr_nmethod(const methodOop m, int bci, int comp_level, bool match_level) const {
2233 // This is a short non-blocking critical region, so the no safepoint check is ok. 2265 // This is a short non-blocking critical region, so the no safepoint check is ok.
2234 OsrList_lock->lock_without_safepoint_check(); 2266 OsrList_lock->lock_without_safepoint_check();
2235 nmethod* osr = osr_nmethods_head(); 2267 nmethod* osr = osr_nmethods_head();
2268 nmethod* best = NULL;
2236 while (osr != NULL) { 2269 while (osr != NULL) {
2237 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain"); 2270 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
2271 // There can be a time when a c1 osr method exists but we are waiting
2272 // for a c2 version. When c2 completes its osr nmethod we will trash
2273 // the c1 version and only be able to find the c2 version. However
2274 // while we overflow in the c1 code at back branches we don't want to
2275 // try and switch to the same code as we are already running
2276
2238 if (osr->method() == m && 2277 if (osr->method() == m &&
2239 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) { 2278 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
2240 // Found a match - return it. 2279 if (match_level) {
2241 OsrList_lock->unlock(); 2280 if (osr->comp_level() == comp_level) {
2242 return osr; 2281 // Found a match - return it.
2282 OsrList_lock->unlock();
2283 return osr;
2284 }
2285 } else {
2286 if (best == NULL || (osr->comp_level() > best->comp_level())) {
2287 if (osr->comp_level() == CompLevel_highest_tier) {
2288 // Found the best possible - return it.
2289 OsrList_lock->unlock();
2290 return osr;
2291 }
2292 best = osr;
2293 }
2294 }
2243 } 2295 }
2244 osr = osr->osr_link(); 2296 osr = osr->osr_link();
2245 } 2297 }
2246 OsrList_lock->unlock(); 2298 OsrList_lock->unlock();
2299 if (best != NULL && best->comp_level() >= comp_level && match_level == false) {
2300 return best;
2301 }
2247 return NULL; 2302 return NULL;
2248 } 2303 }
2249 2304
2250 // ----------------------------------------------------------------------------------------------------- 2305 // -----------------------------------------------------------------------------------------------------
2251 #ifndef PRODUCT 2306 #ifndef PRODUCT