comparison src/share/vm/ci/bcEscapeAnalyzer.cpp @ 1930:2d26b0046e0d

Merge.
author Thomas Wuerthinger <wuerthinger@ssw.jku.at>
date Tue, 30 Nov 2010 14:53:30 +0100
parents 53dbe853fb3a
children f95d63e2154a
comparison
equal deleted inserted replaced
1484:6b7001391c97 1930:2d26b0046e0d
1 /* 1 /*
2 * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. 2 * Copyright (c) 2005, 2009, 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.
14 * 14 *
15 * You should have received a copy of the GNU General Public License version 15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation, 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 * 18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * CA 95054 USA or visit www.sun.com if you need additional information or 20 * or visit www.oracle.com if you need additional information or have any
21 * have any questions. 21 * questions.
22 * 22 *
23 */ 23 */
24 24
25 25
26 #include "incls/_precompiled.incl" 26 #include "incls/_precompiled.incl"
90 90
91 StateInfo() { 91 StateInfo() {
92 empty_map.clear(); 92 empty_map.clear();
93 } 93 }
94 94
95 ArgumentMap raw_pop() { assert(_stack_height > 0, "stack underflow"); return _stack[--_stack_height]; } 95 ArgumentMap raw_pop() { guarantee(_stack_height > 0, "stack underflow"); return _stack[--_stack_height]; }
96 ArgumentMap apop() { return raw_pop(); } 96 ArgumentMap apop() { return raw_pop(); }
97 void spop() { raw_pop(); } 97 void spop() { raw_pop(); }
98 void lpop() { spop(); spop(); } 98 void lpop() { spop(); spop(); }
99 void raw_push(ArgumentMap i) { assert(_stack_height < _max_stack, "stack overflow"); _stack[_stack_height++] = i; } 99 void raw_push(ArgumentMap i) { guarantee(_stack_height < _max_stack, "stack overflow"); _stack[_stack_height++] = i; }
100 void apush(ArgumentMap i) { raw_push(i); } 100 void apush(ArgumentMap i) { raw_push(i); }
101 void spush() { raw_push(empty_map); } 101 void spush() { raw_push(empty_map); }
102 void lpush() { spush(); spush(); } 102 void lpush() { spush(); spush(); }
103 103
104 }; 104 };
105 105
106 void BCEscapeAnalyzer::set_returned(ArgumentMap vars) { 106 void BCEscapeAnalyzer::set_returned(ArgumentMap vars) {
107 for (int i = 0; i < _arg_size; i++) { 107 for (int i = 0; i < _arg_size; i++) {
108 if (vars.contains(i)) 108 if (vars.contains(i))
109 _arg_returned.set_bit(i); 109 _arg_returned.set(i);
110 } 110 }
111 _return_local = _return_local && !(vars.contains_unknown() || vars.contains_allocated()); 111 _return_local = _return_local && !(vars.contains_unknown() || vars.contains_allocated());
112 _return_allocated = _return_allocated && vars.contains_allocated() && !(vars.contains_unknown() || vars.contains_vars()); 112 _return_allocated = _return_allocated && vars.contains_allocated() && !(vars.contains_unknown() || vars.contains_vars());
113 } 113 }
114 114
124 // return true if any element of vars is an arg_stack argument 124 // return true if any element of vars is an arg_stack argument
125 bool BCEscapeAnalyzer::is_arg_stack(ArgumentMap vars){ 125 bool BCEscapeAnalyzer::is_arg_stack(ArgumentMap vars){
126 if (_conservative) 126 if (_conservative)
127 return true; 127 return true;
128 for (int i = 0; i < _arg_size; i++) { 128 for (int i = 0; i < _arg_size; i++) {
129 if (vars.contains(i) && _arg_stack.at(i)) 129 if (vars.contains(i) && _arg_stack.test(i))
130 return true; 130 return true;
131 } 131 }
132 return false; 132 return false;
133 } 133 }
134 134
135 void BCEscapeAnalyzer::clear_bits(ArgumentMap vars, BitMap &bm) { 135 void BCEscapeAnalyzer::clear_bits(ArgumentMap vars, VectorSet &bm) {
136 for (int i = 0; i < _arg_size; i++) { 136 for (int i = 0; i < _arg_size; i++) {
137 if (vars.contains(i)) { 137 if (vars.contains(i)) {
138 bm.clear_bit(i); 138 bm >>= i;
139 } 139 }
140 } 140 }
141 } 141 }
142 142
143 void BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) { 143 void BCEscapeAnalyzer::set_method_escape(ArgumentMap vars) {
363 state.lpush(); 363 state.lpush();
364 break; 364 break;
365 case Bytecodes::_ldc: 365 case Bytecodes::_ldc:
366 case Bytecodes::_ldc_w: 366 case Bytecodes::_ldc_w:
367 case Bytecodes::_ldc2_w: 367 case Bytecodes::_ldc2_w:
368 if (type2size[s.get_constant().basic_type()] == 1) { 368 {
369 // Avoid calling get_constant() which will try to allocate
370 // unloaded constant. We need only constant's type.
371 int index = s.get_constant_pool_index();
372 constantTag tag = s.get_constant_pool_tag(index);
373 if (tag.is_long() || tag.is_double()) {
374 // Only longs and doubles use 2 stack slots.
375 state.lpush();
376 } else {
369 state.spush(); 377 state.spush();
370 } else { 378 }
371 state.lpush(); 379 break;
372 } 380 }
373 break;
374 case Bytecodes::_aload: 381 case Bytecodes::_aload:
375 state.apush(state._vars[s.get_index()]); 382 state.apush(state._vars[s.get_index()]);
376 break; 383 break;
377 case Bytecodes::_iload: 384 case Bytecodes::_iload:
378 case Bytecodes::_fload: 385 case Bytecodes::_fload:
1155 1162
1156 // initialize escape state of object parameters 1163 // initialize escape state of object parameters
1157 ciSignature* sig = method()->signature(); 1164 ciSignature* sig = method()->signature();
1158 int j = 0; 1165 int j = 0;
1159 if (!method()->is_static()) { 1166 if (!method()->is_static()) {
1160 _arg_local.set_bit(0); 1167 _arg_local.set(0);
1161 _arg_stack.set_bit(0); 1168 _arg_stack.set(0);
1162 j++; 1169 j++;
1163 } 1170 }
1164 for (i = 0; i < sig->count(); i++) { 1171 for (i = 0; i < sig->count(); i++) {
1165 ciType* t = sig->type_at(i); 1172 ciType* t = sig->type_at(i);
1166 if (!t->is_primitive_type()) { 1173 if (!t->is_primitive_type()) {
1167 _arg_local.set_bit(j); 1174 _arg_local.set(j);
1168 _arg_stack.set_bit(j); 1175 _arg_stack.set(j);
1169 } 1176 }
1170 j += t->size(); 1177 j += t->size();
1171 } 1178 }
1172 assert(j == _arg_size, "just checking"); 1179 assert(j == _arg_size, "just checking");
1173 1180
1196 var.clear(); 1203 var.clear();
1197 var.set(i); 1204 var.set(i);
1198 set_modified(var, OFFSET_ANY, 4); 1205 set_modified(var, OFFSET_ANY, 4);
1199 set_global_escape(var); 1206 set_global_escape(var);
1200 } 1207 }
1201 _arg_local.clear(); 1208 _arg_local.Clear();
1202 _arg_stack.clear(); 1209 _arg_stack.Clear();
1203 _arg_returned.clear(); 1210 _arg_returned.Clear();
1204 _return_local = false; 1211 _return_local = false;
1205 _return_allocated = false; 1212 _return_allocated = false;
1206 _allocated_escapes = true; 1213 _allocated_escapes = true;
1207 _unknown_modified = true; 1214 _unknown_modified = true;
1208 } 1215 }
1252 1259
1253 initialize(); 1260 initialize();
1254 1261
1255 // Do not scan method if it has no object parameters and 1262 // Do not scan method if it has no object parameters and
1256 // does not returns an object (_return_allocated is set in initialize()). 1263 // does not returns an object (_return_allocated is set in initialize()).
1257 if (_arg_local.is_empty() && !_return_allocated) { 1264 if (_arg_local.Size() == 0 && !_return_allocated) {
1258 // Clear all info since method's bytecode was not analysed and 1265 // Clear all info since method's bytecode was not analysed and
1259 // set pessimistic escape information. 1266 // set pessimistic escape information.
1260 clear_escape_info(); 1267 clear_escape_info();
1261 methodData()->set_eflag(methodDataOopDesc::allocated_escapes); 1268 methodData()->set_eflag(methodDataOopDesc::allocated_escapes);
1262 methodData()->set_eflag(methodDataOopDesc::unknown_modified); 1269 methodData()->set_eflag(methodDataOopDesc::unknown_modified);
1273 // don't store interprocedural escape information if it introduces 1280 // don't store interprocedural escape information if it introduces
1274 // dependencies or if method data is empty 1281 // dependencies or if method data is empty
1275 // 1282 //
1276 if (!has_dependencies() && !methodData()->is_empty()) { 1283 if (!has_dependencies() && !methodData()->is_empty()) {
1277 for (i = 0; i < _arg_size; i++) { 1284 for (i = 0; i < _arg_size; i++) {
1278 if (_arg_local.at(i)) { 1285 if (_arg_local.test(i)) {
1279 assert(_arg_stack.at(i), "inconsistent escape info"); 1286 assert(_arg_stack.test(i), "inconsistent escape info");
1280 methodData()->set_arg_local(i); 1287 methodData()->set_arg_local(i);
1281 methodData()->set_arg_stack(i); 1288 methodData()->set_arg_stack(i);
1282 } else if (_arg_stack.at(i)) { 1289 } else if (_arg_stack.test(i)) {
1283 methodData()->set_arg_stack(i); 1290 methodData()->set_arg_stack(i);
1284 } 1291 }
1285 if (_arg_returned.at(i)) { 1292 if (_arg_returned.test(i)) {
1286 methodData()->set_arg_returned(i); 1293 methodData()->set_arg_returned(i);
1287 } 1294 }
1288 methodData()->set_arg_modified(i, _arg_modified[i]); 1295 methodData()->set_arg_modified(i, _arg_modified[i]);
1289 } 1296 }
1290 if (_return_local) { 1297 if (_return_local) {
1306 void BCEscapeAnalyzer::read_escape_info() { 1313 void BCEscapeAnalyzer::read_escape_info() {
1307 assert(methodData()->has_escape_info(), "no escape info available"); 1314 assert(methodData()->has_escape_info(), "no escape info available");
1308 1315
1309 // read escape information from method descriptor 1316 // read escape information from method descriptor
1310 for (int i = 0; i < _arg_size; i++) { 1317 for (int i = 0; i < _arg_size; i++) {
1311 _arg_local.at_put(i, methodData()->is_arg_local(i)); 1318 if (methodData()->is_arg_local(i))
1312 _arg_stack.at_put(i, methodData()->is_arg_stack(i)); 1319 _arg_local.set(i);
1313 _arg_returned.at_put(i, methodData()->is_arg_returned(i)); 1320 if (methodData()->is_arg_stack(i))
1321 _arg_stack.set(i);
1322 if (methodData()->is_arg_returned(i))
1323 _arg_returned.set(i);
1314 _arg_modified[i] = methodData()->arg_modified(i); 1324 _arg_modified[i] = methodData()->arg_modified(i);
1315 } 1325 }
1316 _return_local = methodData()->eflag_set(methodDataOopDesc::return_local); 1326 _return_local = methodData()->eflag_set(methodDataOopDesc::return_local);
1317 _return_allocated = methodData()->eflag_set(methodDataOopDesc::return_allocated); 1327 _return_allocated = methodData()->eflag_set(methodDataOopDesc::return_allocated);
1318 _allocated_escapes = methodData()->eflag_set(methodDataOopDesc::allocated_escapes); 1328 _allocated_escapes = methodData()->eflag_set(methodDataOopDesc::allocated_escapes);
1356 } 1366 }
1357 #endif 1367 #endif
1358 1368
1359 BCEscapeAnalyzer::BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent) 1369 BCEscapeAnalyzer::BCEscapeAnalyzer(ciMethod* method, BCEscapeAnalyzer* parent)
1360 : _conservative(method == NULL || !EstimateArgEscape) 1370 : _conservative(method == NULL || !EstimateArgEscape)
1371 , _arena(CURRENT_ENV->arena())
1361 , _method(method) 1372 , _method(method)
1362 , _methodData(method ? method->method_data() : NULL) 1373 , _methodData(method ? method->method_data() : NULL)
1363 , _arg_size(method ? method->arg_size() : 0) 1374 , _arg_size(method ? method->arg_size() : 0)
1364 , _stack() 1375 , _arg_local(_arena)
1365 , _arg_local(_arg_size) 1376 , _arg_stack(_arena)
1366 , _arg_stack(_arg_size) 1377 , _arg_returned(_arena)
1367 , _arg_returned(_arg_size) 1378 , _dirty(_arena)
1368 , _dirty(_arg_size)
1369 , _return_local(false) 1379 , _return_local(false)
1370 , _return_allocated(false) 1380 , _return_allocated(false)
1371 , _allocated_escapes(false) 1381 , _allocated_escapes(false)
1372 , _unknown_modified(false) 1382 , _unknown_modified(false)
1373 , _dependencies() 1383 , _dependencies(_arena, 4, 0, NULL)
1374 , _parent(parent) 1384 , _parent(parent)
1375 , _level(parent == NULL ? 0 : parent->level() + 1) { 1385 , _level(parent == NULL ? 0 : parent->level() + 1) {
1376 if (!_conservative) { 1386 if (!_conservative) {
1377 _arg_local.clear(); 1387 _arg_local.Clear();
1378 _arg_stack.clear(); 1388 _arg_stack.Clear();
1379 _arg_returned.clear(); 1389 _arg_returned.Clear();
1380 _dirty.clear(); 1390 _dirty.Clear();
1381 Arena* arena = CURRENT_ENV->arena(); 1391 Arena* arena = CURRENT_ENV->arena();
1382 _arg_modified = (uint *) arena->Amalloc(_arg_size * sizeof(uint)); 1392 _arg_modified = (uint *) arena->Amalloc(_arg_size * sizeof(uint));
1383 Copy::zero_to_bytes(_arg_modified, _arg_size * sizeof(uint)); 1393 Copy::zero_to_bytes(_arg_modified, _arg_size * sizeof(uint));
1384 1394
1385 if (methodData() == NULL) 1395 if (methodData() == NULL)
1412 // Also record evol dependencies so redefinition of the 1422 // Also record evol dependencies so redefinition of the
1413 // callee will trigger recompilation. 1423 // callee will trigger recompilation.
1414 deps->assert_evol_method(method()); 1424 deps->assert_evol_method(method());
1415 } 1425 }
1416 for (int i = 0; i < _dependencies.length(); i+=2) { 1426 for (int i = 0; i < _dependencies.length(); i+=2) {
1417 ciKlass *k = _dependencies[i]->as_klass(); 1427 ciKlass *k = _dependencies.at(i)->as_klass();
1418 ciMethod *m = _dependencies[i+1]->as_method(); 1428 ciMethod *m = _dependencies.at(i+1)->as_method();
1419 deps->assert_unique_concrete_method(k, m); 1429 deps->assert_unique_concrete_method(k, m);
1420 } 1430 }
1421 } 1431 }