comparison src/share/vm/code/dependencies.hpp @ 6725:da91efe96a93

6964458: Reimplement class meta-data storage to use native memory Summary: Remove PermGen, allocate meta-data in metaspace linked to class loaders, rewrite GC walking, rewrite and rename metadata to be C++ classes Reviewed-by: jmasa, stefank, never, coleenp, kvn, brutisso, mgerdin, dholmes, jrose, twisti, roland Contributed-by: jmasa <jon.masamitsu@oracle.com>, stefank <stefan.karlsson@oracle.com>, mgerdin <mikael.gerdin@oracle.com>, never <tom.rodriguez@oracle.com>
author coleenp
date Sat, 01 Sep 2012 13:25:18 -0400
parents b27c72d69fd1
children eec7173947a1 3aaa4b9966f6 3c048df3ef8b 9906d432d6db
comparison
equal deleted inserted replaced
6724:36d1d483d5d6 6725:da91efe96a93
1 /* 1 /*
2 * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2005, 2012, 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.
201 static void check_valid_dependency_type(DepType dept); 201 static void check_valid_dependency_type(DepType dept);
202 202
203 private: 203 private:
204 // State for writing a new set of dependencies: 204 // State for writing a new set of dependencies:
205 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept)) 205 GrowableArray<int>* _dep_seen; // (seen[h->ident] & (1<<dept))
206 GrowableArray<ciObject*>* _deps[TYPE_LIMIT]; 206 GrowableArray<ciBaseObject*>* _deps[TYPE_LIMIT];
207 207
208 static const char* _dep_name[TYPE_LIMIT]; 208 static const char* _dep_name[TYPE_LIMIT];
209 static int _dep_args[TYPE_LIMIT]; 209 static int _dep_args[TYPE_LIMIT];
210 210
211 static bool dept_in_mask(DepType dept, int mask) { 211 static bool dept_in_mask(DepType dept, int mask) {
212 return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0; 212 return (int)dept >= 0 && dept < TYPE_LIMIT && ((1<<dept) & mask) != 0;
213 } 213 }
214 214
215 bool note_dep_seen(int dept, ciObject* x) { 215 bool note_dep_seen(int dept, ciBaseObject* x) {
216 assert(dept < BitsPerInt, "oob"); 216 assert(dept < BitsPerInt, "oob");
217 int x_id = x->ident(); 217 int x_id = x->ident();
218 assert(_dep_seen != NULL, "deps must be writable"); 218 assert(_dep_seen != NULL, "deps must be writable");
219 int seen = _dep_seen->at_grow(x_id, 0); 219 int seen = _dep_seen->at_grow(x_id, 0);
220 _dep_seen->at_put(x_id, seen | (1<<dept)); 220 _dep_seen->at_put(x_id, seen | (1<<dept));
221 // return true if we've already seen dept/x 221 // return true if we've already seen dept/x
222 return (seen & (1<<dept)) != 0; 222 return (seen & (1<<dept)) != 0;
223 } 223 }
224 224
225 bool maybe_merge_ctxk(GrowableArray<ciObject*>* deps, 225 bool maybe_merge_ctxk(GrowableArray<ciBaseObject*>* deps,
226 int ctxk_i, ciKlass* ctxk); 226 int ctxk_i, ciKlass* ctxk);
227 227
228 void sort_all_deps(); 228 void sort_all_deps();
229 size_t estimate_size_in_bytes(); 229 size_t estimate_size_in_bytes();
230 230
258 static void check_ctxk_abstract(ciKlass* ctxk) { 258 static void check_ctxk_abstract(ciKlass* ctxk) {
259 check_ctxk(ctxk); 259 check_ctxk(ctxk);
260 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract"); 260 assert(!is_concrete_klass(ctxk->as_instance_klass()), "must be abstract");
261 } 261 }
262 262
263 void assert_common_1(DepType dept, ciObject* x); 263 void assert_common_1(DepType dept, ciBaseObject* x);
264 void assert_common_2(DepType dept, ciObject* x0, ciObject* x1); 264 void assert_common_2(DepType dept, ciBaseObject* x0, ciBaseObject* x1);
265 void assert_common_3(DepType dept, ciKlass* ctxk, ciObject* x1, ciObject* x2); 265 void assert_common_3(DepType dept, ciKlass* ctxk, ciBaseObject* x1, ciBaseObject* x2);
266 266
267 public: 267 public:
268 // Adding assertions to a new dependency set at compile time: 268 // Adding assertions to a new dependency set at compile time:
269 void assert_evol_method(ciMethod* m); 269 void assert_evol_method(ciMethod* m);
270 void assert_leaf_type(ciKlass* ctxk); 270 void assert_leaf_type(ciKlass* ctxk);
284 // Future optimizations may allow some classes to remain 284 // Future optimizations may allow some classes to remain
285 // non-concrete until their first instantiation, and allow some 285 // non-concrete until their first instantiation, and allow some
286 // methods to remain non-concrete until their first invocation. 286 // methods to remain non-concrete until their first invocation.
287 // In that case, there would be a middle ground between concrete 287 // In that case, there would be a middle ground between concrete
288 // and abstract (as defined by the Java language and VM). 288 // and abstract (as defined by the Java language and VM).
289 static bool is_concrete_klass(klassOop k); // k is instantiable 289 static bool is_concrete_klass(Klass* k); // k is instantiable
290 static bool is_concrete_method(methodOop m); // m is invocable 290 static bool is_concrete_method(Method* m); // m is invocable
291 static Klass* find_finalizable_subclass(Klass* k); 291 static Klass* find_finalizable_subclass(Klass* k);
292 292
293 // These versions of the concreteness queries work through the CI. 293 // These versions of the concreteness queries work through the CI.
294 // The CI versions are allowed to skew sometimes from the VM 294 // The CI versions are allowed to skew sometimes from the VM
295 // (oop-based) versions. The cost of such a difference is a 295 // (oop-based) versions. The cost of such a difference is a
312 // evolution, but that's the logic of the checking.) However, if a 312 // evolution, but that's the logic of the checking.) However, if a
313 // supposedly abstract class or method suddenly becomes concrete, a 313 // supposedly abstract class or method suddenly becomes concrete, a
314 // dependency on it must fail. 314 // dependency on it must fail.
315 315
316 // Checking old assertions at run-time (in the VM only): 316 // Checking old assertions at run-time (in the VM only):
317 static klassOop check_evol_method(methodOop m); 317 static Klass* check_evol_method(Method* m);
318 static klassOop check_leaf_type(klassOop ctxk); 318 static Klass* check_leaf_type(Klass* ctxk);
319 static klassOop check_abstract_with_unique_concrete_subtype(klassOop ctxk, klassOop conck, 319 static Klass* check_abstract_with_unique_concrete_subtype(Klass* ctxk, Klass* conck,
320 KlassDepChange* changes = NULL); 320 KlassDepChange* changes = NULL);
321 static klassOop check_abstract_with_no_concrete_subtype(klassOop ctxk, 321 static Klass* check_abstract_with_no_concrete_subtype(Klass* ctxk,
322 KlassDepChange* changes = NULL); 322 KlassDepChange* changes = NULL);
323 static klassOop check_concrete_with_no_concrete_subtype(klassOop ctxk, 323 static Klass* check_concrete_with_no_concrete_subtype(Klass* ctxk,
324 KlassDepChange* changes = NULL); 324 KlassDepChange* changes = NULL);
325 static klassOop check_unique_concrete_method(klassOop ctxk, methodOop uniqm, 325 static Klass* check_unique_concrete_method(Klass* ctxk, Method* uniqm,
326 KlassDepChange* changes = NULL); 326 KlassDepChange* changes = NULL);
327 static klassOop check_abstract_with_exclusive_concrete_subtypes(klassOop ctxk, klassOop k1, klassOop k2, 327 static Klass* check_abstract_with_exclusive_concrete_subtypes(Klass* ctxk, Klass* k1, Klass* k2,
328 KlassDepChange* changes = NULL); 328 KlassDepChange* changes = NULL);
329 static klassOop check_exclusive_concrete_methods(klassOop ctxk, methodOop m1, methodOop m2, 329 static Klass* check_exclusive_concrete_methods(Klass* ctxk, Method* m1, Method* m2,
330 KlassDepChange* changes = NULL); 330 KlassDepChange* changes = NULL);
331 static klassOop check_has_no_finalizable_subclasses(klassOop ctxk, KlassDepChange* changes = NULL); 331 static Klass* check_has_no_finalizable_subclasses(Klass* ctxk, KlassDepChange* changes = NULL);
332 static klassOop check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = NULL); 332 static Klass* check_call_site_target_value(oop call_site, oop method_handle, CallSiteDepChange* changes = NULL);
333 // A returned klassOop is NULL if the dependency assertion is still 333 // A returned Klass* is NULL if the dependency assertion is still
334 // valid. A non-NULL klassOop is a 'witness' to the assertion 334 // valid. A non-NULL Klass* is a 'witness' to the assertion
335 // failure, a point in the class hierarchy where the assertion has 335 // failure, a point in the class hierarchy where the assertion has
336 // been proven false. For example, if check_leaf_type returns 336 // been proven false. For example, if check_leaf_type returns
337 // non-NULL, the value is a subtype of the supposed leaf type. This 337 // non-NULL, the value is a subtype of the supposed leaf type. This
338 // witness value may be useful for logging the dependency failure. 338 // witness value may be useful for logging the dependency failure.
339 // Note that, when a dependency fails, there may be several possible 339 // Note that, when a dependency fails, there may be several possible
343 // The 'changes' value, if non-null, requests a limited spot-check 343 // The 'changes' value, if non-null, requests a limited spot-check
344 // near the indicated recent changes in the class hierarchy. 344 // near the indicated recent changes in the class hierarchy.
345 // It is used by DepStream::spot_check_dependency_at. 345 // It is used by DepStream::spot_check_dependency_at.
346 346
347 // Detecting possible new assertions: 347 // Detecting possible new assertions:
348 static klassOop find_unique_concrete_subtype(klassOop ctxk); 348 static Klass* find_unique_concrete_subtype(Klass* ctxk);
349 static methodOop find_unique_concrete_method(klassOop ctxk, methodOop m); 349 static Method* find_unique_concrete_method(Klass* ctxk, Method* m);
350 static int find_exclusive_concrete_subtypes(klassOop ctxk, int klen, klassOop k[]); 350 static int find_exclusive_concrete_subtypes(Klass* ctxk, int klen, Klass* k[]);
351 static int find_exclusive_concrete_methods(klassOop ctxk, int mlen, methodOop m[]); 351 static int find_exclusive_concrete_methods(Klass* ctxk, int mlen, Method* m[]);
352 352
353 // Create the encoding which will be stored in an nmethod. 353 // Create the encoding which will be stored in an nmethod.
354 void encode_content_bytes(); 354 void encode_content_bytes();
355 355
356 address content_bytes() { 356 address content_bytes() {
366 CompileLog* log() { return _log; } 366 CompileLog* log() { return _log; }
367 367
368 void copy_to(nmethod* nm); 368 void copy_to(nmethod* nm);
369 369
370 void log_all_dependencies(); 370 void log_all_dependencies();
371 void log_dependency(DepType dept, int nargs, ciObject* args[]) { 371 void log_dependency(DepType dept, int nargs, ciBaseObject* args[]) {
372 write_dependency_to(log(), dept, nargs, args); 372 write_dependency_to(log(), dept, nargs, args);
373 } 373 }
374 void log_dependency(DepType dept, 374 void log_dependency(DepType dept,
375 ciObject* x0, 375 ciBaseObject* x0,
376 ciObject* x1 = NULL, 376 ciBaseObject* x1 = NULL,
377 ciObject* x2 = NULL) { 377 ciBaseObject* x2 = NULL) {
378 if (log() == NULL) return; 378 if (log() == NULL) return;
379 ciObject* args[max_arg_count]; 379 ciBaseObject* args[max_arg_count];
380 args[0] = x0; 380 args[0] = x0;
381 args[1] = x1; 381 args[1] = x1;
382 args[2] = x2; 382 args[2] = x2;
383 assert(2 < max_arg_count, ""); 383 assert(2 < max_arg_count, "");
384 log_dependency(dept, dep_args(dept), args); 384 log_dependency(dept, dep_args(dept), args);
385 } 385 }
386 386
387 class DepArgument : public ResourceObj {
388 private:
389 bool _is_oop;
390 bool _valid;
391 void* _value;
392 public:
393 DepArgument() : _is_oop(false), _value(NULL), _valid(false) {}
394 DepArgument(oop v): _is_oop(true), _value(v), _valid(true) {}
395 DepArgument(Metadata* v): _is_oop(false), _value(v), _valid(true) {}
396
397 bool is_null() const { return _value == NULL; }
398 bool is_oop() const { return _is_oop; }
399 bool is_metadata() const { return !_is_oop; }
400 bool is_klass() const { return is_metadata() && metadata_value()->is_klass(); }
401 bool is_method() const { return is_metadata() && metadata_value()->is_method(); }
402
403 oop oop_value() const { assert(_is_oop && _valid, "must be"); return (oop) _value; }
404 Metadata* metadata_value() const { assert(!_is_oop && _valid, "must be"); return (Metadata*) _value; }
405 };
406
387 static void write_dependency_to(CompileLog* log, 407 static void write_dependency_to(CompileLog* log,
388 DepType dept, 408 DepType dept,
389 int nargs, ciObject* args[], 409 int nargs, ciBaseObject* args[],
390 klassOop witness = NULL); 410 Klass* witness = NULL);
391 static void write_dependency_to(CompileLog* log, 411 static void write_dependency_to(CompileLog* log,
392 DepType dept, 412 DepType dept,
393 int nargs, oop args[], 413 int nargs, DepArgument args[],
394 klassOop witness = NULL); 414 Klass* witness = NULL);
395 static void write_dependency_to(xmlStream* xtty, 415 static void write_dependency_to(xmlStream* xtty,
396 DepType dept, 416 DepType dept,
397 int nargs, oop args[], 417 int nargs, DepArgument args[],
398 klassOop witness = NULL); 418 Klass* witness = NULL);
399 static void print_dependency(DepType dept, 419 static void print_dependency(DepType dept,
400 int nargs, oop args[], 420 int nargs, DepArgument args[],
401 klassOop witness = NULL); 421 Klass* witness = NULL);
402 422
403 private: 423 private:
404 // helper for encoding common context types as zero: 424 // helper for encoding common context types as zero:
405 static ciKlass* ctxk_encoded_as_null(DepType dept, ciObject* x); 425 static ciKlass* ctxk_encoded_as_null(DepType dept, ciBaseObject* x);
406 426
407 static klassOop ctxk_encoded_as_null(DepType dept, oop x); 427 static Klass* ctxk_encoded_as_null(DepType dept, Metadata* x);
408 428
409 public: 429 public:
410 // Use this to iterate over an nmethod's dependency set. 430 // Use this to iterate over an nmethod's dependency set.
411 // Works on new and old dependency sets. 431 // Works on new and old dependency sets.
412 // Usage: 432 // Usage:
431 DepType _type; 451 DepType _type;
432 int _xi[max_arg_count+1]; 452 int _xi[max_arg_count+1];
433 453
434 void initial_asserts(size_t byte_limit) NOT_DEBUG({}); 454 void initial_asserts(size_t byte_limit) NOT_DEBUG({});
435 455
456 inline Metadata* recorded_metadata_at(int i);
436 inline oop recorded_oop_at(int i); 457 inline oop recorded_oop_at(int i);
437 // => _code? _code->oop_at(i): *_deps->_oop_recorder->handle_at(i) 458
438 459 Klass* check_klass_dependency(KlassDepChange* changes);
439 klassOop check_klass_dependency(KlassDepChange* changes); 460 Klass* check_call_site_dependency(CallSiteDepChange* changes);
440 klassOop check_call_site_dependency(CallSiteDepChange* changes); 461
441 462 void trace_and_log_witness(Klass* witness);
442 void trace_and_log_witness(klassOop witness);
443 463
444 public: 464 public:
445 DepStream(Dependencies* deps) 465 DepStream(Dependencies* deps)
446 : _deps(deps), 466 : _deps(deps),
447 _code(NULL), 467 _code(NULL),
461 481
462 DepType type() { return _type; } 482 DepType type() { return _type; }
463 int argument_count() { return dep_args(type()); } 483 int argument_count() { return dep_args(type()); }
464 int argument_index(int i) { assert(0 <= i && i < argument_count(), "oob"); 484 int argument_index(int i) { assert(0 <= i && i < argument_count(), "oob");
465 return _xi[i]; } 485 return _xi[i]; }
466 oop argument(int i); // => recorded_oop_at(argument_index(i)) 486 Metadata* argument(int i); // => recorded_oop_at(argument_index(i))
467 klassOop context_type(); 487 oop argument_oop(int i); // => recorded_oop_at(argument_index(i))
488 Klass* context_type();
468 489
469 bool is_klass_type() { return Dependencies::is_klass_type(type()); } 490 bool is_klass_type() { return Dependencies::is_klass_type(type()); }
470 491
471 methodOop method_argument(int i) { 492 Method* method_argument(int i) {
472 oop x = argument(i); 493 Metadata* x = argument(i);
473 assert(x->is_method(), "type"); 494 assert(x->is_method(), "type");
474 return (methodOop) x; 495 return (Method*) x;
475 } 496 }
476 klassOop type_argument(int i) { 497 Klass* type_argument(int i) {
477 oop x = argument(i); 498 Metadata* x = argument(i);
478 assert(x->is_klass(), "type"); 499 assert(x->is_klass(), "type");
479 return (klassOop) x; 500 return (Klass*) x;
480 } 501 }
481 502
482 // The point of the whole exercise: Is this dep still OK? 503 // The point of the whole exercise: Is this dep still OK?
483 klassOop check_dependency() { 504 Klass* check_dependency() {
484 klassOop result = check_klass_dependency(NULL); 505 Klass* result = check_klass_dependency(NULL);
485 if (result != NULL) return result; 506 if (result != NULL) return result;
486 return check_call_site_dependency(NULL); 507 return check_call_site_dependency(NULL);
487 } 508 }
488 509
489 // A lighter version: Checks only around recent changes in a class 510 // A lighter version: Checks only around recent changes in a class
490 // hierarchy. (See Universe::flush_dependents_on.) 511 // hierarchy. (See Universe::flush_dependents_on.)
491 klassOop spot_check_dependency_at(DepChange& changes); 512 Klass* spot_check_dependency_at(DepChange& changes);
492 513
493 // Log the current dependency to xtty or compilation log. 514 // Log the current dependency to xtty or compilation log.
494 void log_dependency(klassOop witness = NULL); 515 void log_dependency(Klass* witness = NULL);
495 516
496 // Print the current dependency to tty. 517 // Print the current dependency to tty.
497 void print_dependency(klassOop witness = NULL, bool verbose = false); 518 void print_dependency(Klass* witness = NULL, bool verbose = false);
498 }; 519 };
499 friend class Dependencies::DepStream; 520 friend class Dependencies::DepStream;
500 521
501 static void print_statistics() PRODUCT_RETURN; 522 static void print_statistics() PRODUCT_RETURN;
502 }; 523 };
531 Start_Klass = CHANGE_LIMIT // internal indicator for ContextStream 552 Start_Klass = CHANGE_LIMIT // internal indicator for ContextStream
532 }; 553 };
533 554
534 // Usage: 555 // Usage:
535 // for (DepChange::ContextStream str(changes); str.next(); ) { 556 // for (DepChange::ContextStream str(changes); str.next(); ) {
536 // klassOop k = str.klass(); 557 // Klass* k = str.klass();
537 // switch (str.change_type()) { 558 // switch (str.change_type()) {
538 // ... 559 // ...
539 // } 560 // }
540 // } 561 // }
541 class ContextStream : public StackObj { 562 class ContextStream : public StackObj {
543 DepChange& _changes; 564 DepChange& _changes;
544 friend class DepChange; 565 friend class DepChange;
545 566
546 // iteration variables: 567 // iteration variables:
547 ChangeType _change_type; 568 ChangeType _change_type;
548 klassOop _klass; 569 Klass* _klass;
549 objArrayOop _ti_base; // i.e., transitive_interfaces 570 Array<Klass*>* _ti_base; // i.e., transitive_interfaces
550 int _ti_index; 571 int _ti_index;
551 int _ti_limit; 572 int _ti_limit;
552 573
553 // start at the beginning: 574 // start at the beginning:
554 void start(); 575 void start();
564 { start(); } 585 { start(); }
565 586
566 bool next(); 587 bool next();
567 588
568 ChangeType change_type() { return _change_type; } 589 ChangeType change_type() { return _change_type; }
569 klassOop klass() { return _klass; } 590 Klass* klass() { return _klass; }
570 }; 591 };
571 friend class DepChange::ContextStream; 592 friend class DepChange::ContextStream;
572 }; 593 };
573 594
574 595
596 ~KlassDepChange(); 617 ~KlassDepChange();
597 618
598 // What kind of DepChange is this? 619 // What kind of DepChange is this?
599 virtual bool is_klass_change() const { return true; } 620 virtual bool is_klass_change() const { return true; }
600 621
601 klassOop new_type() { return _new_type(); } 622 Klass* new_type() { return _new_type(); }
602 623
603 // involves_context(k) is true if k is new_type or any of the super types 624 // involves_context(k) is true if k is new_type or any of the super types
604 bool involves_context(klassOop k); 625 bool involves_context(Klass* k);
605 }; 626 };
606 627
607 628
608 // A CallSite has changed its target. 629 // A CallSite has changed its target.
609 class CallSiteDepChange : public DepChange { 630 class CallSiteDepChange : public DepChange {