Mercurial > hg > graal-compiler
comparison src/share/vm/code/dependencies.cpp @ 7094:eec7173947a1
removed remaining use of the C++ "compiler interface" (i.e. ci) by Graal for installing dependencies
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 29 Nov 2012 17:13:13 +0100 |
parents | 80e866b1d053 |
children | 0778b04fc682 |
comparison
equal
deleted
inserted
replaced
7093:dff79b1f82f1 | 7094:eec7173947a1 |
---|---|
48 void Dependencies::initialize(ciEnv* env) { | 48 void Dependencies::initialize(ciEnv* env) { |
49 Arena* arena = env->arena(); | 49 Arena* arena = env->arena(); |
50 _oop_recorder = env->oop_recorder(); | 50 _oop_recorder = env->oop_recorder(); |
51 _log = env->log(); | 51 _log = env->log(); |
52 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0); | 52 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0); |
53 #ifdef GRAAL | |
54 _using_dep_values = false; | |
55 #endif // GRAAL | |
53 DEBUG_ONLY(_deps[end_marker] = NULL); | 56 DEBUG_ONLY(_deps[end_marker] = NULL); |
54 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { | 57 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { |
55 _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, 0); | 58 _deps[i] = new(arena) GrowableArray<ciBaseObject*>(arena, 10, 0, 0); |
56 } | 59 } |
57 _content_bytes = NULL; | 60 _content_bytes = NULL; |
116 | 119 |
117 void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) { | 120 void Dependencies::assert_call_site_target_value(ciCallSite* call_site, ciMethodHandle* method_handle) { |
118 check_ctxk(call_site->klass()); | 121 check_ctxk(call_site->klass()); |
119 assert_common_2(call_site_target_value, call_site, method_handle); | 122 assert_common_2(call_site_target_value, call_site, method_handle); |
120 } | 123 } |
124 | |
125 #ifdef GRAAL | |
126 | |
127 Dependencies::Dependencies(Arena* arena, OopRecorder* oop_recorder) { | |
128 _oop_recorder = oop_recorder; | |
129 _log = NULL; | |
130 _dep_seen = new(arena) GrowableArray<int>(arena, 500, 0, 0); | |
131 _using_dep_values = true; | |
132 DEBUG_ONLY(_dep_values[end_marker] = NULL); | |
133 for (int i = (int)FIRST_TYPE; i < (int)TYPE_LIMIT; i++) { | |
134 _dep_values[i] = new(arena) GrowableArray<DepValue>(arena, 10, 0, DepValue()); | |
135 } | |
136 _content_bytes = NULL; | |
137 _size_in_bytes = (size_t)-1; | |
138 | |
139 assert(TYPE_LIMIT <= (1<<LG2_TYPE_LIMIT), "sanity"); | |
140 } | |
141 | |
142 void Dependencies::assert_evol_method(DepValue m) { | |
143 assert_common_1(evol_method, m); | |
144 } | |
145 | |
146 void Dependencies::assert_leaf_type(DepValue ctxk_dv) { | |
147 Klass* ctxk = ctxk_dv.as_klass(); | |
148 if (ctxk->oop_is_array()) { | |
149 // As a special case, support this assertion on an array type, | |
150 // which reduces to an assertion on its element type. | |
151 // Note that this cannot be done with assertions that | |
152 // relate to concreteness or abstractness. | |
153 BasicType elemt = ArrayKlass::cast(ctxk)->element_type(); | |
154 if (is_java_primitive(elemt)) return; // Ex: int[][] | |
155 ctxk = ObjArrayKlass::cast(ctxk)->bottom_klass(); | |
156 //if (ctxk->is_final()) return; // Ex: String[][] | |
157 } | |
158 check_ctxk(ctxk); | |
159 assert_common_1(leaf_type, ctxk_dv); | |
160 } | |
161 | |
162 void Dependencies::assert_abstract_with_unique_concrete_subtype(DepValue ctxk, DepValue conck) { | |
163 check_ctxk_abstract(ctxk.as_klass()); | |
164 assert_common_2(abstract_with_unique_concrete_subtype, ctxk, conck); | |
165 } | |
166 | |
167 void Dependencies::assert_unique_concrete_method(DepValue ctxk, DepValue uniqm) { | |
168 check_ctxk(ctxk.as_klass()); | |
169 assert_common_2(unique_concrete_method, ctxk, uniqm); | |
170 } | |
171 #endif // GRAAL | |
172 | |
121 | 173 |
122 // Helper function. If we are adding a new dep. under ctxk2, | 174 // Helper function. If we are adding a new dep. under ctxk2, |
123 // try to find an old dep. under a broader* ctxk1. If there is | 175 // try to find an old dep. under a broader* ctxk1. If there is |
124 // | 176 // |
125 bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps, | 177 bool Dependencies::maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps, |
228 deps->append(ctxk); | 280 deps->append(ctxk); |
229 deps->append(x); | 281 deps->append(x); |
230 deps->append(x2); | 282 deps->append(x2); |
231 } | 283 } |
232 | 284 |
285 #ifdef GRAAL | |
286 bool Dependencies::maybe_merge_ctxk(GrowableArray<DepValue>* deps, | |
287 int ctxk_i, DepValue ctxk2_dv) { | |
288 Klass* ctxk1 = deps->at(ctxk_i).as_klass(); | |
289 Klass* ctxk2 = ctxk2_dv.as_klass(); | |
290 if (ctxk2->is_subtype_of(ctxk1)) { | |
291 return true; // success, and no need to change | |
292 } else if (ctxk1->is_subtype_of(ctxk2)) { | |
293 // new context class fully subsumes previous one | |
294 deps->at_put(ctxk_i, ctxk2_dv); | |
295 return true; | |
296 } else { | |
297 return false; | |
298 } | |
299 } | |
300 | |
301 void Dependencies::assert_common_1(DepType dept, DepValue x) { | |
302 assert(dep_args(dept) == 1, "sanity"); | |
303 //log_dependency(dept, x); | |
304 GrowableArray<DepValue>* deps = _dep_values[dept]; | |
305 | |
306 // see if the same (or a similar) dep is already recorded | |
307 if (note_dep_seen(dept, x)) { | |
308 assert(deps->find(x) >= 0, "sanity"); | |
309 } else { | |
310 deps->append(x); | |
311 } | |
312 } | |
313 | |
314 void Dependencies::assert_common_2(DepType dept, | |
315 DepValue x0, DepValue x1) { | |
316 assert(dep_args(dept) == 2, "sanity"); | |
317 //log_dependency(dept, x0, x1); | |
318 GrowableArray<DepValue>* deps = _dep_values[dept]; | |
319 | |
320 // see if the same (or a similar) dep is already recorded | |
321 bool has_ctxk = has_explicit_context_arg(dept); | |
322 if (has_ctxk) { | |
323 assert(dep_context_arg(dept) == 0, "sanity"); | |
324 if (note_dep_seen(dept, x1)) { | |
325 // look in this bucket for redundant assertions | |
326 const int stride = 2; | |
327 for (int i = deps->length(); (i -= stride) >= 0; ) { | |
328 DepValue y1 = deps->at(i+1); | |
329 if (x1 == y1) { // same subject; check the context | |
330 if (maybe_merge_ctxk(deps, i+0, x0)) { | |
331 return; | |
332 } | |
333 } | |
334 } | |
335 } | |
336 } else { | |
337 assert(dep_implicit_context_arg(dept) == 0, "sanity"); | |
338 if (note_dep_seen(dept, x0) && note_dep_seen(dept, x1)) { | |
339 // look in this bucket for redundant assertions | |
340 const int stride = 2; | |
341 for (int i = deps->length(); (i -= stride) >= 0; ) { | |
342 DepValue y0 = deps->at(i+0); | |
343 DepValue y1 = deps->at(i+1); | |
344 if (x0 == y0 && x1 == y1) { | |
345 return; | |
346 } | |
347 } | |
348 } | |
349 } | |
350 | |
351 // append the assertion in the correct bucket: | |
352 deps->append(x0); | |
353 deps->append(x1); | |
354 } | |
355 #endif // GRAAL | |
356 | |
233 /// Support for encoding dependencies into an nmethod: | 357 /// Support for encoding dependencies into an nmethod: |
234 | 358 |
235 void Dependencies::copy_to(nmethod* nm) { | 359 void Dependencies::copy_to(nmethod* nm) { |
236 address beg = nm->dependencies_begin(); | 360 address beg = nm->dependencies_begin(); |
237 address end = nm->dependencies_end(); | 361 address end = nm->dependencies_end(); |
254 static int sort_dep_arg_2(ciBaseObject** p1, ciBaseObject** p2) | 378 static int sort_dep_arg_2(ciBaseObject** p1, ciBaseObject** p2) |
255 { return sort_dep(p1, p2, 2); } | 379 { return sort_dep(p1, p2, 2); } |
256 static int sort_dep_arg_3(ciBaseObject** p1, ciBaseObject** p2) | 380 static int sort_dep_arg_3(ciBaseObject** p1, ciBaseObject** p2) |
257 { return sort_dep(p1, p2, 3); } | 381 { return sort_dep(p1, p2, 3); } |
258 | 382 |
383 #ifdef GRAAL | |
384 // metadata deps are sorted before object deps | |
385 static int sort_dep_value(DepValue* p1, DepValue* p2, int narg) { | |
386 for (int i = 0; i < narg; i++) { | |
387 int diff = p1[i].sort_key() - p2[i].sort_key(); | |
388 if (diff != 0) return diff; | |
389 } | |
390 return 0; | |
391 } | |
392 static int sort_dep_value_arg_1(DepValue* p1, DepValue* p2) | |
393 { return sort_dep_value(p1, p2, 1); } | |
394 static int sort_dep_value_arg_2(DepValue* p1, DepValue* p2) | |
395 { return sort_dep_value(p1, p2, 2); } | |
396 static int sort_dep_value_arg_3(DepValue* p1, DepValue* p2) | |
397 { return sort_dep_value(p1, p2, 3); } | |
398 #endif // GRAAL | |
399 | |
259 void Dependencies::sort_all_deps() { | 400 void Dependencies::sort_all_deps() { |
401 #ifdef GRAAL | |
402 if (_using_dep_values) { | |
403 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
404 DepType dept = (DepType)deptv; | |
405 GrowableArray<DepValue>* deps = _dep_values[dept]; | |
406 if (deps->length() <= 1) continue; | |
407 switch (dep_args(dept)) { | |
408 case 1: deps->sort(sort_dep_value_arg_1, 1); break; | |
409 case 2: deps->sort(sort_dep_value_arg_2, 2); break; | |
410 case 3: deps->sort(sort_dep_value_arg_3, 3); break; | |
411 default: ShouldNotReachHere(); | |
412 } | |
413 } | |
414 return; | |
415 } | |
416 #endif // GRAAL | |
260 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | 417 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
261 DepType dept = (DepType)deptv; | 418 DepType dept = (DepType)deptv; |
262 GrowableArray<ciBaseObject*>* deps = _deps[dept]; | 419 GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
263 if (deps->length() <= 1) continue; | 420 if (deps->length() <= 1) continue; |
264 switch (dep_args(dept)) { | 421 switch (dep_args(dept)) { |
270 } | 427 } |
271 } | 428 } |
272 | 429 |
273 size_t Dependencies::estimate_size_in_bytes() { | 430 size_t Dependencies::estimate_size_in_bytes() { |
274 size_t est_size = 100; | 431 size_t est_size = 100; |
432 #ifdef GRAAL | |
433 if (_using_dep_values) { | |
434 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
435 DepType dept = (DepType)deptv; | |
436 GrowableArray<DepValue>* deps = _dep_values[dept]; | |
437 est_size += deps->length() * 2; // tags and argument(s) | |
438 } | |
439 return est_size; | |
440 } | |
441 #endif // GRAAL | |
275 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | 442 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
276 DepType dept = (DepType)deptv; | 443 DepType dept = (DepType)deptv; |
277 GrowableArray<ciBaseObject*>* deps = _deps[dept]; | 444 GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
278 est_size += deps->length()*2; // tags and argument(s) | 445 est_size += deps->length()*2; // tags and argument(s) |
279 } | 446 } |
309 sort_all_deps(); | 476 sort_all_deps(); |
310 | 477 |
311 // cast is safe, no deps can overflow INT_MAX | 478 // cast is safe, no deps can overflow INT_MAX |
312 CompressedWriteStream bytes((int)estimate_size_in_bytes()); | 479 CompressedWriteStream bytes((int)estimate_size_in_bytes()); |
313 | 480 |
481 #ifdef GRAAL | |
482 if (_using_dep_values) { | |
483 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | |
484 DepType dept = (DepType)deptv; | |
485 GrowableArray<DepValue>* deps = _dep_values[dept]; | |
486 if (deps->length() == 0) continue; | |
487 int stride = dep_args(dept); | |
488 int ctxkj = dep_context_arg(dept); // -1 if no context arg | |
489 assert(stride > 0, "sanity"); | |
490 for (int i = 0; i < deps->length(); i += stride) { | |
491 jbyte code_byte = (jbyte)dept; | |
492 int skipj = -1; | |
493 if (ctxkj >= 0 && ctxkj+1 < stride) { | |
494 Klass* ctxk = deps->at(i+ctxkj+0).as_klass(); | |
495 DepValue x = deps->at(i+ctxkj+1); // following argument | |
496 if (ctxk == ctxk_encoded_as_null(dept, x.as_metadata())) { | |
497 skipj = ctxkj; // we win: maybe one less oop to keep track of | |
498 code_byte |= default_context_type_bit; | |
499 } | |
500 } | |
501 bytes.write_byte(code_byte); | |
502 for (int j = 0; j < stride; j++) { | |
503 if (j == skipj) continue; | |
504 DepValue v = deps->at(i+j); | |
505 int idx = v.index(); | |
506 bytes.write_int(idx); | |
507 } | |
508 } | |
509 } | |
510 } else { | |
511 #endif // GRAAL | |
314 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { | 512 for (int deptv = (int)FIRST_TYPE; deptv < (int)TYPE_LIMIT; deptv++) { |
315 DepType dept = (DepType)deptv; | 513 DepType dept = (DepType)deptv; |
316 GrowableArray<ciBaseObject*>* deps = _deps[dept]; | 514 GrowableArray<ciBaseObject*>* deps = _deps[dept]; |
317 if (deps->length() == 0) continue; | 515 if (deps->length() == 0) continue; |
318 int stride = dep_args(dept); | 516 int stride = dep_args(dept); |
342 } | 540 } |
343 bytes.write_int(idx); | 541 bytes.write_int(idx); |
344 } | 542 } |
345 } | 543 } |
346 } | 544 } |
545 #ifdef GRAAL | |
546 } | |
547 #endif // GRAAL | |
347 | 548 |
348 // write a sentinel byte to mark the end | 549 // write a sentinel byte to mark the end |
349 bytes.write_byte(end_marker); | 550 bytes.write_byte(end_marker); |
350 | 551 |
351 // round it out to a word boundary | 552 // round it out to a word boundary |
357 assert((jbyte)default_context_type_bit != 0, "byte overflow"); | 558 assert((jbyte)default_context_type_bit != 0, "byte overflow"); |
358 | 559 |
359 _content_bytes = bytes.buffer(); | 560 _content_bytes = bytes.buffer(); |
360 _size_in_bytes = bytes.position(); | 561 _size_in_bytes = bytes.position(); |
361 } | 562 } |
362 | |
363 | 563 |
364 const char* Dependencies::_dep_name[TYPE_LIMIT] = { | 564 const char* Dependencies::_dep_name[TYPE_LIMIT] = { |
365 "end_marker", | 565 "end_marker", |
366 "evol_method", | 566 "evol_method", |
367 "leaf_type", | 567 "leaf_type", |