Merge

Fri, 11 Mar 2011 21:19:15 -0800

author
jrose
date
Fri, 11 Mar 2011 21:19:15 -0800
changeset 2637
799d8ccf63cf
parent 2618
df1347358fe6
parent 2636
83f08886981c
child 2638
72dee110246f

Merge

src/share/vm/oops/methodOop.hpp file | annotate | diff | comparison | revisions
src/share/vm/runtime/arguments.cpp file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/c1/c1_Canonicalizer.cpp	Mon Mar 07 16:03:28 2011 -0500
     1.2 +++ b/src/share/vm/c1/c1_Canonicalizer.cpp	Fri Mar 11 21:19:15 2011 -0800
     1.3 @@ -209,7 +209,7 @@
     1.4      // limit this optimization to current block
     1.5      if (value != NULL && in_current_block(conv)) {
     1.6        set_canonical(new StoreField(x->obj(), x->offset(), x->field(), value, x->is_static(),
     1.7 -                                       x->state_before(), x->is_loaded(), x->is_initialized()));
     1.8 +                                   x->state_before(), x->needs_patching()));
     1.9        return;
    1.10      }
    1.11    }
     2.1 --- a/src/share/vm/c1/c1_GraphBuilder.cpp	Mon Mar 07 16:03:28 2011 -0500
     2.2 +++ b/src/share/vm/c1/c1_GraphBuilder.cpp	Fri Mar 11 21:19:15 2011 -0800
     2.3 @@ -1456,12 +1456,12 @@
     2.4    BasicType field_type = field->type()->basic_type();
     2.5    ValueType* type = as_ValueType(field_type);
     2.6    // call will_link again to determine if the field is valid.
     2.7 -  const bool is_loaded = holder->is_loaded() &&
     2.8 -                         field->will_link(method()->holder(), code);
     2.9 -  const bool is_initialized = is_loaded && holder->is_initialized();
    2.10 +  const bool needs_patching = !holder->is_loaded() ||
    2.11 +                              !field->will_link(method()->holder(), code) ||
    2.12 +                              PatchALot;
    2.13  
    2.14    ValueStack* state_before = NULL;
    2.15 -  if (!is_initialized || PatchALot) {
    2.16 +  if (!holder->is_initialized() || needs_patching) {
    2.17      // save state before instruction for debug info when
    2.18      // deoptimization happens during patching
    2.19      state_before = copy_state_before();
    2.20 @@ -1469,10 +1469,6 @@
    2.21  
    2.22    Value obj = NULL;
    2.23    if (code == Bytecodes::_getstatic || code == Bytecodes::_putstatic) {
    2.24 -    // commoning of class constants should only occur if the class is
    2.25 -    // fully initialized and resolved in this constant pool.  The will_link test
    2.26 -    // above essentially checks if this class is resolved in this constant pool
    2.27 -    // so, the is_initialized flag should be suffiect.
    2.28      if (state_before != NULL) {
    2.29        // build a patching constant
    2.30        obj = new Constant(new ClassConstant(holder), state_before);
    2.31 @@ -1482,7 +1478,7 @@
    2.32    }
    2.33  
    2.34  
    2.35 -  const int offset = is_loaded ? field->offset() : -1;
    2.36 +  const int offset = !needs_patching ? field->offset() : -1;
    2.37    switch (code) {
    2.38      case Bytecodes::_getstatic: {
    2.39        // check for compile-time constants, i.e., initialized static final fields
    2.40 @@ -1509,7 +1505,7 @@
    2.41            state_before = copy_state_for_exception();
    2.42          }
    2.43          push(type, append(new LoadField(append(obj), offset, field, true,
    2.44 -                                        state_before, is_loaded, is_initialized)));
    2.45 +                                        state_before, needs_patching)));
    2.46        }
    2.47        break;
    2.48      }
    2.49 @@ -1518,7 +1514,7 @@
    2.50          if (state_before == NULL) {
    2.51            state_before = copy_state_for_exception();
    2.52          }
    2.53 -        append(new StoreField(append(obj), offset, field, val, true, state_before, is_loaded, is_initialized));
    2.54 +        append(new StoreField(append(obj), offset, field, val, true, state_before, needs_patching));
    2.55        }
    2.56        break;
    2.57      case Bytecodes::_getfield :
    2.58 @@ -1526,8 +1522,8 @@
    2.59          if (state_before == NULL) {
    2.60            state_before = copy_state_for_exception();
    2.61          }
    2.62 -        LoadField* load = new LoadField(apop(), offset, field, false, state_before, is_loaded, true);
    2.63 -        Value replacement = is_loaded ? _memory->load(load) : load;
    2.64 +        LoadField* load = new LoadField(apop(), offset, field, false, state_before, needs_patching);
    2.65 +        Value replacement = !needs_patching ? _memory->load(load) : load;
    2.66          if (replacement != load) {
    2.67            assert(replacement->is_linked() || !replacement->can_be_linked(), "should already by linked");
    2.68            push(type, replacement);
    2.69 @@ -1542,8 +1538,8 @@
    2.70          if (state_before == NULL) {
    2.71            state_before = copy_state_for_exception();
    2.72          }
    2.73 -        StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, is_loaded, true);
    2.74 -        if (is_loaded) store = _memory->store(store);
    2.75 +        StoreField* store = new StoreField(apop(), offset, field, val, false, state_before, needs_patching);
    2.76 +        if (!needs_patching) store = _memory->store(store);
    2.77          if (store != NULL) {
    2.78            append(store);
    2.79          }
     3.1 --- a/src/share/vm/c1/c1_Instruction.hpp	Mon Mar 07 16:03:28 2011 -0500
     3.2 +++ b/src/share/vm/c1/c1_Instruction.hpp	Fri Mar 11 21:19:15 2011 -0800
     3.3 @@ -323,8 +323,6 @@
     3.4      CanTrapFlag,
     3.5      DirectCompareFlag,
     3.6      IsEliminatedFlag,
     3.7 -    IsInitializedFlag,
     3.8 -    IsLoadedFlag,
     3.9      IsSafepointFlag,
    3.10      IsStaticFlag,
    3.11      IsStrictfpFlag,
    3.12 @@ -693,7 +691,7 @@
    3.13   public:
    3.14    // creation
    3.15    AccessField(Value obj, int offset, ciField* field, bool is_static,
    3.16 -              ValueStack* state_before, bool is_loaded, bool is_initialized)
    3.17 +              ValueStack* state_before, bool needs_patching)
    3.18    : Instruction(as_ValueType(field->type()->basic_type()), state_before)
    3.19    , _obj(obj)
    3.20    , _offset(offset)
    3.21 @@ -701,16 +699,9 @@
    3.22    , _explicit_null_check(NULL)
    3.23    {
    3.24      set_needs_null_check(!is_static);
    3.25 -    set_flag(IsLoadedFlag, is_loaded);
    3.26 -    set_flag(IsInitializedFlag, is_initialized);
    3.27      set_flag(IsStaticFlag, is_static);
    3.28 +    set_flag(NeedsPatchingFlag, needs_patching);
    3.29      ASSERT_VALUES
    3.30 -      if (!is_loaded || (PatchALot && !field->is_volatile())) {
    3.31 -      // need to patch if the holder wasn't loaded or we're testing
    3.32 -      // using PatchALot.  Don't allow PatchALot for fields which are
    3.33 -      // known to be volatile they aren't patchable.
    3.34 -      set_flag(NeedsPatchingFlag, true);
    3.35 -    }
    3.36      // pin of all instructions with memory access
    3.37      pin();
    3.38    }
    3.39 @@ -721,11 +712,14 @@
    3.40    ciField* field() const                         { return _field; }
    3.41    BasicType field_type() const                   { return _field->type()->basic_type(); }
    3.42    bool is_static() const                         { return check_flag(IsStaticFlag); }
    3.43 -  bool is_loaded() const                         { return check_flag(IsLoadedFlag); }
    3.44 -  bool is_initialized() const                    { return check_flag(IsInitializedFlag); }
    3.45    NullCheck* explicit_null_check() const         { return _explicit_null_check; }
    3.46    bool needs_patching() const                    { return check_flag(NeedsPatchingFlag); }
    3.47  
    3.48 +  // Unresolved getstatic and putstatic can cause initialization.
    3.49 +  // Technically it occurs at the Constant that materializes the base
    3.50 +  // of the static fields but it's simpler to model it here.
    3.51 +  bool is_init_point() const                     { return is_static() && (needs_patching() || !_field->holder()->is_initialized()); }
    3.52 +
    3.53    // manipulation
    3.54  
    3.55    // Under certain circumstances, if a previous NullCheck instruction
    3.56 @@ -745,15 +739,15 @@
    3.57   public:
    3.58    // creation
    3.59    LoadField(Value obj, int offset, ciField* field, bool is_static,
    3.60 -            ValueStack* state_before, bool is_loaded, bool is_initialized)
    3.61 -  : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized)
    3.62 +            ValueStack* state_before, bool needs_patching)
    3.63 +  : AccessField(obj, offset, field, is_static, state_before, needs_patching)
    3.64    {}
    3.65  
    3.66    ciType* declared_type() const;
    3.67    ciType* exact_type() const;
    3.68  
    3.69    // generic
    3.70 -  HASHING2(LoadField, is_loaded() && !field()->is_volatile(), obj()->subst(), offset())  // cannot be eliminated if not yet loaded or if volatile
    3.71 +  HASHING2(LoadField, !needs_patching() && !field()->is_volatile(), obj()->subst(), offset())  // cannot be eliminated if needs patching or if volatile
    3.72  };
    3.73  
    3.74  
    3.75 @@ -764,8 +758,8 @@
    3.76   public:
    3.77    // creation
    3.78    StoreField(Value obj, int offset, ciField* field, Value value, bool is_static,
    3.79 -             ValueStack* state_before, bool is_loaded, bool is_initialized)
    3.80 -  : AccessField(obj, offset, field, is_static, state_before, is_loaded, is_initialized)
    3.81 +             ValueStack* state_before, bool needs_patching)
    3.82 +  : AccessField(obj, offset, field, is_static, state_before, needs_patching)
    3.83    , _value(value)
    3.84    {
    3.85      set_flag(NeedsWriteBarrierFlag, as_ValueType(field_type())->is_object());
     4.1 --- a/src/share/vm/c1/c1_LIRGenerator.cpp	Mon Mar 07 16:03:28 2011 -0500
     4.2 +++ b/src/share/vm/c1/c1_LIRGenerator.cpp	Fri Mar 11 21:19:15 2011 -0800
     4.3 @@ -1559,9 +1559,7 @@
     4.4                  (info ? new CodeEmitInfo(info) : NULL));
     4.5    }
     4.6  
     4.7 -  if (is_volatile) {
     4.8 -    assert(!needs_patching && x->is_loaded(),
     4.9 -           "how do we know it's volatile if it's not loaded");
    4.10 +  if (is_volatile && !needs_patching) {
    4.11      volatile_field_store(value.result(), address, info);
    4.12    } else {
    4.13      LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
    4.14 @@ -1627,9 +1625,7 @@
    4.15      address = generate_address(object.result(), x->offset(), field_type);
    4.16    }
    4.17  
    4.18 -  if (is_volatile) {
    4.19 -    assert(!needs_patching && x->is_loaded(),
    4.20 -           "how do we know it's volatile if it's not loaded");
    4.21 +  if (is_volatile && !needs_patching) {
    4.22      volatile_field_load(address, reg, info);
    4.23    } else {
    4.24      LIR_PatchCode patch_code = needs_patching ? lir_patch_normal : lir_patch_none;
     5.1 --- a/src/share/vm/c1/c1_ValueMap.hpp	Mon Mar 07 16:03:28 2011 -0500
     5.2 +++ b/src/share/vm/c1/c1_ValueMap.hpp	Fri Mar 11 21:19:15 2011 -0800
     5.3 @@ -141,7 +141,8 @@
     5.4  
     5.5    // visitor functions
     5.6    void do_StoreField     (StoreField*      x) {
     5.7 -    if (!x->is_initialized()) {
     5.8 +    if (x->is_init_point()) {
     5.9 +      // putstatic is an initialization point so treat it as a wide kill
    5.10        kill_memory();
    5.11      } else {
    5.12        kill_field(x->field());
    5.13 @@ -159,7 +160,8 @@
    5.14    void do_Local          (Local*           x) { /* nothing to do */ }
    5.15    void do_Constant       (Constant*        x) { /* nothing to do */ }
    5.16    void do_LoadField      (LoadField*       x) {
    5.17 -    if (!x->is_initialized()) {
    5.18 +    if (x->is_init_point()) {
    5.19 +      // getstatic is an initialization point so treat it as a wide kill
    5.20        kill_memory();
    5.21      }
    5.22    }
     6.1 --- a/src/share/vm/code/codeCache.cpp	Mon Mar 07 16:03:28 2011 -0500
     6.2 +++ b/src/share/vm/code/codeCache.cpp	Fri Mar 11 21:19:15 2011 -0800
     6.3 @@ -939,9 +939,16 @@
     6.4                 _heap->high(),
     6.5                 _heap->high_boundary());
     6.6    st->print_cr(" total_blobs=" UINT32_FORMAT " nmethods=" UINT32_FORMAT
     6.7 -               " adapters=" UINT32_FORMAT " free_code_cache=" SIZE_FORMAT
     6.8 +               " adapters=" UINT32_FORMAT " free_code_cache=" SIZE_FORMAT "Kb"
     6.9                 " largest_free_block=" SIZE_FORMAT,
    6.10 -               CodeCache::nof_blobs(), CodeCache::nof_nmethods(),
    6.11 -               CodeCache::nof_adapters(), CodeCache::unallocated_capacity(),
    6.12 -               CodeCache::largest_free_block());
    6.13 +               nof_blobs(), nof_nmethods(), nof_adapters(),
    6.14 +               unallocated_capacity()/K, largest_free_block());
    6.15  }
    6.16 +
    6.17 +void CodeCache::log_state(outputStream* st) {
    6.18 +  st->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
    6.19 +            " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'"
    6.20 +            " largest_free_block='" SIZE_FORMAT "'",
    6.21 +            nof_blobs(), nof_nmethods(), nof_adapters(),
    6.22 +            unallocated_capacity(), largest_free_block());
    6.23 +}
     7.1 --- a/src/share/vm/code/codeCache.hpp	Mon Mar 07 16:03:28 2011 -0500
     7.2 +++ b/src/share/vm/code/codeCache.hpp	Fri Mar 11 21:19:15 2011 -0800
     7.3 @@ -147,6 +147,7 @@
     7.4    static void verify();                          // verifies the code cache
     7.5    static void print_trace(const char* event, CodeBlob* cb, int size = 0) PRODUCT_RETURN;
     7.6    static void print_bounds(outputStream* st);    // Prints a summary of the bounds of the code cache
     7.7 +  static void log_state(outputStream* st);
     7.8  
     7.9    // The full limits of the codeCache
    7.10    static address  low_bound()                    { return (address) _heap->low_boundary(); }
    7.11 @@ -159,7 +160,7 @@
    7.12    static size_t  max_capacity()                  { return _heap->max_capacity(); }
    7.13    static size_t  unallocated_capacity()          { return _heap->unallocated_capacity(); }
    7.14    static size_t  largest_free_block()            { return _heap->largest_free_block(); }
    7.15 -  static bool    needs_flushing()                { return unallocated_capacity() < CodeCacheFlushingMinimumFreeSpace; }
    7.16 +  static bool    needs_flushing()                { return largest_free_block() < CodeCacheFlushingMinimumFreeSpace; }
    7.17  
    7.18    static bool needs_cache_clean()                { return _needs_cache_clean; }
    7.19    static void set_needs_cache_clean(bool v)      { _needs_cache_clean = v;    }
     8.1 --- a/src/share/vm/code/nmethod.cpp	Mon Mar 07 16:03:28 2011 -0500
     8.2 +++ b/src/share/vm/code/nmethod.cpp	Fri Mar 11 21:19:15 2011 -0800
     8.3 @@ -762,7 +762,7 @@
     8.4  
     8.5  void* nmethod::operator new(size_t size, int nmethod_size) {
     8.6    // Always leave some room in the CodeCache for I2C/C2I adapters
     8.7 -  if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) return NULL;
     8.8 +  if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL;
     8.9    return CodeCache::allocate(nmethod_size);
    8.10  }
    8.11  
    8.12 @@ -1881,7 +1881,7 @@
    8.13  
    8.14  
    8.15  oop nmethod::embeddedOop_at(u_char* p) {
    8.16 -  RelocIterator iter(this, p, p + oopSize);
    8.17 +  RelocIterator iter(this, p, p + 1);
    8.18    while (iter.next())
    8.19      if (iter.type() == relocInfo::oop_type) {
    8.20        return iter.oop_reloc()->oop_value();
     9.1 --- a/src/share/vm/compiler/compileBroker.cpp	Mon Mar 07 16:03:28 2011 -0500
     9.2 +++ b/src/share/vm/compiler/compileBroker.cpp	Fri Mar 11 21:19:15 2011 -0800
     9.3 @@ -1364,7 +1364,7 @@
     9.4        // We need this HandleMark to avoid leaking VM handles.
     9.5        HandleMark hm(thread);
     9.6  
     9.7 -      if (CodeCache::unallocated_capacity() < CodeCacheMinimumFreeSpace) {
     9.8 +      if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) {
     9.9          // the code cache is really full
    9.10          handle_full_code_cache();
    9.11        } else if (UseCodeCacheFlushing && CodeCache::needs_flushing()) {
    9.12 @@ -1645,11 +1645,13 @@
    9.13    if (UseCompiler || AlwaysCompileLoopMethods ) {
    9.14      if (xtty != NULL) {
    9.15        xtty->begin_elem("code_cache_full");
    9.16 +      CodeCache::log_state(xtty);
    9.17        xtty->stamp();
    9.18        xtty->end_elem();
    9.19      }
    9.20      warning("CodeCache is full. Compiler has been disabled.");
    9.21      warning("Try increasing the code cache size using -XX:ReservedCodeCacheSize=");
    9.22 +    CodeCache::print_bounds(tty);
    9.23  #ifndef PRODUCT
    9.24      if (CompileTheWorld || ExitOnFullCodeCache) {
    9.25        before_exit(JavaThread::current());
    10.1 --- a/src/share/vm/memory/heap.cpp	Mon Mar 07 16:03:28 2011 -0500
    10.2 +++ b/src/share/vm/memory/heap.cpp	Fri Mar 11 21:19:15 2011 -0800
    10.3 @@ -316,12 +316,19 @@
    10.4  }
    10.5  
    10.6  size_t CodeHeap::largest_free_block() const {
    10.7 +  // First check unused space excluding free blocks.
    10.8 +  size_t free_sz = size(_free_segments);
    10.9 +  size_t unused  = max_capacity() - allocated_capacity() - free_sz;
   10.10 +  if (unused >= free_sz)
   10.11 +    return unused;
   10.12 +
   10.13 +  // Now check largest free block.
   10.14    size_t len = 0;
   10.15    for (FreeBlock* b = _freelist; b != NULL; b = b->link()) {
   10.16      if (b->length() > len)
   10.17        len = b->length();
   10.18    }
   10.19 -  return size(len);
   10.20 +  return MAX2(unused, size(len));
   10.21  }
   10.22  
   10.23  // Free list management
    11.1 --- a/src/share/vm/oops/methodKlass.cpp	Mon Mar 07 16:03:28 2011 -0500
    11.2 +++ b/src/share/vm/oops/methodKlass.cpp	Fri Mar 11 21:19:15 2011 -0800
    11.3 @@ -103,6 +103,12 @@
    11.4    m->backedge_counter()->init();
    11.5    m->clear_number_of_breakpoints();
    11.6  
    11.7 +#ifdef TIERED
    11.8 +  m->set_rate(0);
    11.9 +  m->set_prev_event_count(0);
   11.10 +  m->set_prev_time(0);
   11.11 +#endif
   11.12 +
   11.13    assert(m->is_parsable(), "must be parsable here.");
   11.14    assert(m->size() == size, "wrong size for object");
   11.15    // We should not publish an uprasable object's reference
    12.1 --- a/src/share/vm/oops/methodOop.hpp	Mon Mar 07 16:03:28 2011 -0500
    12.2 +++ b/src/share/vm/oops/methodOop.hpp	Fri Mar 11 21:19:15 2011 -0800
    12.3 @@ -84,6 +84,11 @@
    12.4  // | invocation_counter                                   |
    12.5  // | backedge_counter                                     |
    12.6  // |------------------------------------------------------|
    12.7 +// |           prev_time (tiered only, 64 bit wide)       |
    12.8 +// |                                                      |
    12.9 +// |------------------------------------------------------|
   12.10 +// |                  rate (tiered)                       |
   12.11 +// |------------------------------------------------------|
   12.12  // | code                           (pointer)             |
   12.13  // | i2i                            (pointer)             |
   12.14  // | adapter                        (pointer)             |
   12.15 @@ -124,6 +129,11 @@
   12.16    InvocationCounter _invocation_counter;         // Incremented before each activation of the method - used to trigger frequency-based optimizations
   12.17    InvocationCounter _backedge_counter;           // Incremented before each backedge taken - used to trigger frequencey-based optimizations
   12.18  
   12.19 +#ifdef TIERED
   12.20 +  jlong             _prev_time;                   // Previous time the rate was acquired
   12.21 +  float             _rate;                        // Events (invocation and backedge counter increments) per millisecond
   12.22 +#endif
   12.23 +
   12.24  #ifndef PRODUCT
   12.25    int               _compiled_invocation_count;  // Number of nmethod invocations so far (for perf. debugging)
   12.26  #endif
   12.27 @@ -304,6 +314,17 @@
   12.28    InvocationCounter* invocation_counter() { return &_invocation_counter; }
   12.29    InvocationCounter* backedge_counter()   { return &_backedge_counter; }
   12.30  
   12.31 +#ifdef TIERED
   12.32 +  // We are reusing interpreter_invocation_count as a holder for the previous event count!
   12.33 +  // We can do that since interpreter_invocation_count is not used in tiered.
   12.34 +  int prev_event_count() const                   { return _interpreter_invocation_count;  }
   12.35 +  void set_prev_event_count(int count)           { _interpreter_invocation_count = count; }
   12.36 +  jlong prev_time() const                        { return _prev_time; }
   12.37 +  void set_prev_time(jlong time)                 { _prev_time = time; }
   12.38 +  float rate() const                             { return _rate; }
   12.39 +  void set_rate(float rate)                      { _rate = rate; }
   12.40 +#endif
   12.41 +
   12.42    int invocation_count();
   12.43    int backedge_count();
   12.44  
    13.1 --- a/src/share/vm/opto/output.cpp	Mon Mar 07 16:03:28 2011 -0500
    13.2 +++ b/src/share/vm/opto/output.cpp	Fri Mar 11 21:19:15 2011 -0800
    13.3 @@ -1028,7 +1028,7 @@
    13.4  
    13.5  // helper for Fill_buffer bailout logic
    13.6  static void turn_off_compiler(Compile* C) {
    13.7 -  if (CodeCache::unallocated_capacity() >= CodeCacheMinimumFreeSpace*10) {
    13.8 +  if (CodeCache::largest_free_block() >= CodeCacheMinimumFreeSpace*10) {
    13.9      // Do not turn off compilation if a single giant method has
   13.10      // blown the code cache size.
   13.11      C->record_failure("excessive request to CodeCache");
    14.1 --- a/src/share/vm/opto/type.cpp	Mon Mar 07 16:03:28 2011 -0500
    14.2 +++ b/src/share/vm/opto/type.cpp	Fri Mar 11 21:19:15 2011 -0800
    14.3 @@ -3386,7 +3386,22 @@
    14.4          instance_id = InstanceBot;
    14.5          tary = TypeAry::make(Type::BOTTOM, tary->_size);
    14.6        }
    14.7 +    } else // Non integral arrays.
    14.8 +    // Must fall to bottom if exact klasses in upper lattice
    14.9 +    // are not equal or super klass is exact.
   14.10 +    if ( above_centerline(ptr) && klass() != tap->klass() &&
   14.11 +         // meet with top[] and bottom[] are processed further down:
   14.12 +         tap ->_klass != NULL  && this->_klass != NULL   &&
   14.13 +         // both are exact and not equal:
   14.14 +        ((tap ->_klass_is_exact && this->_klass_is_exact) ||
   14.15 +         // 'tap'  is exact and super or unrelated:
   14.16 +         (tap ->_klass_is_exact && !tap->klass()->is_subtype_of(klass())) ||
   14.17 +         // 'this' is exact and super or unrelated:
   14.18 +         (this->_klass_is_exact && !klass()->is_subtype_of(tap->klass())))) {
   14.19 +      tary = TypeAry::make(Type::BOTTOM, tary->_size);
   14.20 +      return make( NotNull, NULL, tary, lazy_klass, false, off, InstanceBot );
   14.21      }
   14.22 +
   14.23      bool xk = false;
   14.24      switch (tap->ptr()) {
   14.25      case AnyNull:
   14.26 @@ -3766,7 +3781,7 @@
   14.27    // Oops, need to compute _klass and cache it
   14.28    ciKlass* k_ary = compute_klass();
   14.29  
   14.30 -  if( this != TypeAryPtr::OOPS ) {
   14.31 +  if( this != TypeAryPtr::OOPS && this->dual() != TypeAryPtr::OOPS ) {
   14.32      // The _klass field acts as a cache of the underlying
   14.33      // ciKlass for this array type.  In order to set the field,
   14.34      // we need to cast away const-ness.
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/share/vm/runtime/advancedThresholdPolicy.cpp	Fri Mar 11 21:19:15 2011 -0800
    15.3 @@ -0,0 +1,450 @@
    15.4 +/*
    15.5 +* Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved.
    15.6 +* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    15.7 +*/
    15.8 +
    15.9 +#include "precompiled.hpp"
   15.10 +#include "runtime/advancedThresholdPolicy.hpp"
   15.11 +#include "runtime/simpleThresholdPolicy.inline.hpp"
   15.12 +
   15.13 +#ifdef TIERED
   15.14 +// Print an event.
   15.15 +void AdvancedThresholdPolicy::print_specific(EventType type, methodHandle mh, methodHandle imh,
   15.16 +                                             int bci, CompLevel level) {
   15.17 +  tty->print(" rate: ");
   15.18 +  if (mh->prev_time() == 0) tty->print("n/a");
   15.19 +  else tty->print("%f", mh->rate());
   15.20 +
   15.21 +  tty->print(" k: %.2lf,%.2lf", threshold_scale(CompLevel_full_profile, Tier3LoadFeedback),
   15.22 +                                threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback));
   15.23 +
   15.24 +}
   15.25 +
   15.26 +void AdvancedThresholdPolicy::initialize() {
   15.27 +  // Turn on ergonomic compiler count selection
   15.28 +  if (FLAG_IS_DEFAULT(CICompilerCountPerCPU) && FLAG_IS_DEFAULT(CICompilerCount)) {
   15.29 +    FLAG_SET_DEFAULT(CICompilerCountPerCPU, true);
   15.30 +  }
   15.31 +  int count = CICompilerCount;
   15.32 +  if (CICompilerCountPerCPU) {
   15.33 +    // Simple log n seems to grow too slowly for tiered, try something faster: log n * log log n
   15.34 +    int log_cpu = log2_intptr(os::active_processor_count());
   15.35 +    int loglog_cpu = log2_intptr(MAX2(log_cpu, 1));
   15.36 +    count = MAX2(log_cpu * loglog_cpu, 1) * 3 / 2;
   15.37 +  }
   15.38 +
   15.39 +  set_c1_count(MAX2(count / 3, 1));
   15.40 +  set_c2_count(MAX2(count - count / 3, 1));
   15.41 +
   15.42 +  // Some inlining tuning
   15.43 +#ifdef X86
   15.44 +  if (FLAG_IS_DEFAULT(InlineSmallCode)) {
   15.45 +    FLAG_SET_DEFAULT(InlineSmallCode, 2000);
   15.46 +  }
   15.47 +#endif
   15.48 +
   15.49 +#ifdef SPARC
   15.50 +  if (FLAG_IS_DEFAULT(InlineSmallCode)) {
   15.51 +    FLAG_SET_DEFAULT(InlineSmallCode, 2500);
   15.52 +  }
   15.53 +#endif
   15.54 +
   15.55 +
   15.56 +  set_start_time(os::javaTimeMillis());
   15.57 +}
   15.58 +
   15.59 +// update_rate() is called from select_task() while holding a compile queue lock.
   15.60 +void AdvancedThresholdPolicy::update_rate(jlong t, methodOop m) {
   15.61 +  if (is_old(m)) {
   15.62 +    // We don't remove old methods from the queue,
   15.63 +    // so we can just zero the rate.
   15.64 +    m->set_rate(0);
   15.65 +    return;
   15.66 +  }
   15.67 +
   15.68 +  // We don't update the rate if we've just came out of a safepoint.
   15.69 +  // delta_s is the time since last safepoint in milliseconds.
   15.70 +  jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
   15.71 +  jlong delta_t = t - (m->prev_time() != 0 ? m->prev_time() : start_time()); // milliseconds since the last measurement
   15.72 +  // How many events were there since the last time?
   15.73 +  int event_count = m->invocation_count() + m->backedge_count();
   15.74 +  int delta_e = event_count - m->prev_event_count();
   15.75 +
   15.76 +  // We should be running for at least 1ms.
   15.77 +  if (delta_s >= TieredRateUpdateMinTime) {
   15.78 +    // And we must've taken the previous point at least 1ms before.
   15.79 +    if (delta_t >= TieredRateUpdateMinTime && delta_e > 0) {
   15.80 +      m->set_prev_time(t);
   15.81 +      m->set_prev_event_count(event_count);
   15.82 +      m->set_rate((float)delta_e / (float)delta_t); // Rate is events per millisecond
   15.83 +    } else
   15.84 +      if (delta_t > TieredRateUpdateMaxTime && delta_e == 0) {
   15.85 +        // If nothing happened for 25ms, zero the rate. Don't modify prev values.
   15.86 +        m->set_rate(0);
   15.87 +      }
   15.88 +  }
   15.89 +}
   15.90 +
   15.91 +// Check if this method has been stale from a given number of milliseconds.
   15.92 +// See select_task().
   15.93 +bool AdvancedThresholdPolicy::is_stale(jlong t, jlong timeout, methodOop m) {
   15.94 +  jlong delta_s = t - SafepointSynchronize::end_of_last_safepoint();
   15.95 +  jlong delta_t = t - m->prev_time();
   15.96 +  if (delta_t > timeout && delta_s > timeout) {
   15.97 +    int event_count = m->invocation_count() + m->backedge_count();
   15.98 +    int delta_e = event_count - m->prev_event_count();
   15.99 +    // Return true if there were no events.
  15.100 +    return delta_e == 0;
  15.101 +  }
  15.102 +  return false;
  15.103 +}
  15.104 +
  15.105 +// We don't remove old methods from the compile queue even if they have
  15.106 +// very low activity. See select_task().
  15.107 +bool AdvancedThresholdPolicy::is_old(methodOop method) {
  15.108 +  return method->invocation_count() > 50000 || method->backedge_count() > 500000;
  15.109 +}
  15.110 +
  15.111 +double AdvancedThresholdPolicy::weight(methodOop method) {
  15.112 +  return (method->rate() + 1) * ((method->invocation_count() + 1) *  (method->backedge_count() + 1));
  15.113 +}
  15.114 +
  15.115 +// Apply heuristics and return true if x should be compiled before y
  15.116 +bool AdvancedThresholdPolicy::compare_methods(methodOop x, methodOop y) {
  15.117 +  if (x->highest_comp_level() > y->highest_comp_level()) {
  15.118 +    // recompilation after deopt
  15.119 +    return true;
  15.120 +  } else
  15.121 +    if (x->highest_comp_level() == y->highest_comp_level()) {
  15.122 +      if (weight(x) > weight(y)) {
  15.123 +        return true;
  15.124 +      }
  15.125 +    }
  15.126 +  return false;
  15.127 +}
  15.128 +
  15.129 +// Is method profiled enough?
  15.130 +bool AdvancedThresholdPolicy::is_method_profiled(methodOop method) {
  15.131 +  methodDataOop mdo = method->method_data();
  15.132 +  if (mdo != NULL) {
  15.133 +    int i = mdo->invocation_count_delta();
  15.134 +    int b = mdo->backedge_count_delta();
  15.135 +    return call_predicate_helper<CompLevel_full_profile>(i, b, 1);
  15.136 +  }
  15.137 +  return false;
  15.138 +}
  15.139 +
  15.140 +// Called with the queue locked and with at least one element
  15.141 +CompileTask* AdvancedThresholdPolicy::select_task(CompileQueue* compile_queue) {
  15.142 +  CompileTask *max_task = NULL;
  15.143 +  methodOop max_method;
  15.144 +  jlong t = os::javaTimeMillis();
  15.145 +  // Iterate through the queue and find a method with a maximum rate.
  15.146 +  for (CompileTask* task = compile_queue->first(); task != NULL;) {
  15.147 +    CompileTask* next_task = task->next();
  15.148 +    methodOop method = (methodOop)JNIHandles::resolve(task->method_handle());
  15.149 +    methodDataOop mdo = method->method_data();
  15.150 +    update_rate(t, method);
  15.151 +    if (max_task == NULL) {
  15.152 +      max_task = task;
  15.153 +      max_method = method;
  15.154 +    } else {
  15.155 +      // If a method has been stale for some time, remove it from the queue.
  15.156 +      if (is_stale(t, TieredCompileTaskTimeout, method) && !is_old(method)) {
  15.157 +        if (PrintTieredEvents) {
  15.158 +          print_event(KILL, method, method, task->osr_bci(), (CompLevel)task->comp_level());
  15.159 +        }
  15.160 +        CompileTaskWrapper ctw(task); // Frees the task
  15.161 +        compile_queue->remove(task);
  15.162 +        method->clear_queued_for_compilation();
  15.163 +        task = next_task;
  15.164 +        continue;
  15.165 +      }
  15.166 +
  15.167 +      // Select a method with a higher rate
  15.168 +      if (compare_methods(method, max_method)) {
  15.169 +        max_task = task;
  15.170 +        max_method = method;
  15.171 +      }
  15.172 +    }
  15.173 +    task = next_task;
  15.174 +  }
  15.175 +
  15.176 +  if (max_task->comp_level() == CompLevel_full_profile && is_method_profiled(max_method)) {
  15.177 +    max_task->set_comp_level(CompLevel_limited_profile);
  15.178 +    if (PrintTieredEvents) {
  15.179 +      print_event(UPDATE, max_method, max_method, max_task->osr_bci(), (CompLevel)max_task->comp_level());
  15.180 +    }
  15.181 +  }
  15.182 +
  15.183 +  return max_task;
  15.184 +}
  15.185 +
  15.186 +double AdvancedThresholdPolicy::threshold_scale(CompLevel level, int feedback_k) {
  15.187 +  double queue_size = CompileBroker::queue_size(level);
  15.188 +  int comp_count = compiler_count(level);
  15.189 +  double k = queue_size / (feedback_k * comp_count) + 1;
  15.190 +  return k;
  15.191 +}
  15.192 +
  15.193 +// Call and loop predicates determine whether a transition to a higher
  15.194 +// compilation level should be performed (pointers to predicate functions
  15.195 +// are passed to common()).
  15.196 +// Tier?LoadFeedback is basically a coefficient that determines of
  15.197 +// how many methods per compiler thread can be in the queue before
  15.198 +// the threshold values double.
  15.199 +bool AdvancedThresholdPolicy::loop_predicate(int i, int b, CompLevel cur_level) {
  15.200 +  switch(cur_level) {
  15.201 +  case CompLevel_none:
  15.202 +  case CompLevel_limited_profile: {
  15.203 +    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
  15.204 +    return loop_predicate_helper<CompLevel_none>(i, b, k);
  15.205 +  }
  15.206 +  case CompLevel_full_profile: {
  15.207 +    double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
  15.208 +    return loop_predicate_helper<CompLevel_full_profile>(i, b, k);
  15.209 +  }
  15.210 +  default:
  15.211 +    return true;
  15.212 +  }
  15.213 +}
  15.214 +
  15.215 +bool AdvancedThresholdPolicy::call_predicate(int i, int b, CompLevel cur_level) {
  15.216 +  switch(cur_level) {
  15.217 +  case CompLevel_none:
  15.218 +  case CompLevel_limited_profile: {
  15.219 +    double k = threshold_scale(CompLevel_full_profile, Tier3LoadFeedback);
  15.220 +    return call_predicate_helper<CompLevel_none>(i, b, k);
  15.221 +  }
  15.222 +  case CompLevel_full_profile: {
  15.223 +    double k = threshold_scale(CompLevel_full_optimization, Tier4LoadFeedback);
  15.224 +    return call_predicate_helper<CompLevel_full_profile>(i, b, k);
  15.225 +  }
  15.226 +  default:
  15.227 +    return true;
  15.228 +  }
  15.229 +}
  15.230 +
  15.231 +// If a method is old enough and is still in the interpreter we would want to
  15.232 +// start profiling without waiting for the compiled method to arrive.
  15.233 +// We also take the load on compilers into the account.
  15.234 +bool AdvancedThresholdPolicy::should_create_mdo(methodOop method, CompLevel cur_level) {
  15.235 +  if (cur_level == CompLevel_none &&
  15.236 +      CompileBroker::queue_size(CompLevel_full_optimization) <=
  15.237 +      Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
  15.238 +    int i = method->invocation_count();
  15.239 +    int b = method->backedge_count();
  15.240 +    double k = Tier0ProfilingStartPercentage / 100.0;
  15.241 +    return call_predicate_helper<CompLevel_none>(i, b, k) || loop_predicate_helper<CompLevel_none>(i, b, k);
  15.242 +  }
  15.243 +  return false;
  15.244 +}
  15.245 +
  15.246 +// Create MDO if necessary.
  15.247 +void AdvancedThresholdPolicy::create_mdo(methodHandle mh, TRAPS) {
  15.248 +  if (mh->is_native() || mh->is_abstract() || mh->is_accessor()) return;
  15.249 +  if (mh->method_data() == NULL) {
  15.250 +    methodOopDesc::build_interpreter_method_data(mh, THREAD);
  15.251 +    if (HAS_PENDING_EXCEPTION) {
  15.252 +      CLEAR_PENDING_EXCEPTION;
  15.253 +    }
  15.254 +  }
  15.255 +}
  15.256 +
  15.257 +
  15.258 +/*
  15.259 + * Method states:
  15.260 + *   0 - interpreter (CompLevel_none)
  15.261 + *   1 - pure C1 (CompLevel_simple)
  15.262 + *   2 - C1 with invocation and backedge counting (CompLevel_limited_profile)
  15.263 + *   3 - C1 with full profiling (CompLevel_full_profile)
  15.264 + *   4 - C2 (CompLevel_full_optimization)
  15.265 + *
  15.266 + * Common state transition patterns:
  15.267 + * a. 0 -> 3 -> 4.
  15.268 + *    The most common path. But note that even in this straightforward case
  15.269 + *    profiling can start at level 0 and finish at level 3.
  15.270 + *
  15.271 + * b. 0 -> 2 -> 3 -> 4.
  15.272 + *    This case occures when the load on C2 is deemed too high. So, instead of transitioning
  15.273 + *    into state 3 directly and over-profiling while a method is in the C2 queue we transition to
  15.274 + *    level 2 and wait until the load on C2 decreases. This path is disabled for OSRs.
  15.275 + *
  15.276 + * c. 0 -> (3->2) -> 4.
  15.277 + *    In this case we enqueue a method for compilation at level 3, but the C1 queue is long enough
  15.278 + *    to enable the profiling to fully occur at level 0. In this case we change the compilation level
  15.279 + *    of the method to 2, because it'll allow it to run much faster without full profiling while c2
  15.280 + *    is compiling.
  15.281 + *
  15.282 + * d. 0 -> 3 -> 1 or 0 -> 2 -> 1.
  15.283 + *    After a method was once compiled with C1 it can be identified as trivial and be compiled to
  15.284 + *    level 1. These transition can also occur if a method can't be compiled with C2 but can with C1.
  15.285 + *
  15.286 + * e. 0 -> 4.
  15.287 + *    This can happen if a method fails C1 compilation (it will still be profiled in the interpreter)
  15.288 + *    or because of a deopt that didn't require reprofiling (compilation won't happen in this case because
  15.289 + *    the compiled version already exists).
  15.290 + *
  15.291 + * Note that since state 0 can be reached from any other state via deoptimization different loops
  15.292 + * are possible.
  15.293 + *
  15.294 + */
  15.295 +
  15.296 +// Common transition function. Given a predicate determines if a method should transition to another level.
  15.297 +CompLevel AdvancedThresholdPolicy::common(Predicate p, methodOop method, CompLevel cur_level) {
  15.298 +  if (is_trivial(method)) return CompLevel_simple;
  15.299 +
  15.300 +  CompLevel next_level = cur_level;
  15.301 +  int i = method->invocation_count();
  15.302 +  int b = method->backedge_count();
  15.303 +
  15.304 +  switch(cur_level) {
  15.305 +  case CompLevel_none:
  15.306 +    // If we were at full profile level, would we switch to full opt?
  15.307 +    if (common(p, method, CompLevel_full_profile) == CompLevel_full_optimization) {
  15.308 +      next_level = CompLevel_full_optimization;
  15.309 +    } else if ((this->*p)(i, b, cur_level)) {
  15.310 +      // C1-generated fully profiled code is about 30% slower than the limited profile
  15.311 +      // code that has only invocation and backedge counters. The observation is that
  15.312 +      // if C2 queue is large enough we can spend too much time in the fully profiled code
  15.313 +      // while waiting for C2 to pick the method from the queue. To alleviate this problem
  15.314 +      // we introduce a feedback on the C2 queue size. If the C2 queue is sufficiently long
  15.315 +      // we choose to compile a limited profiled version and then recompile with full profiling
  15.316 +      // when the load on C2 goes down.
  15.317 +      if (CompileBroker::queue_size(CompLevel_full_optimization) >
  15.318 +          Tier3DelayOn * compiler_count(CompLevel_full_optimization)) {
  15.319 +        next_level = CompLevel_limited_profile;
  15.320 +      } else {
  15.321 +        next_level = CompLevel_full_profile;
  15.322 +      }
  15.323 +    }
  15.324 +    break;
  15.325 +  case CompLevel_limited_profile:
  15.326 +    if (is_method_profiled(method)) {
  15.327 +      // Special case: we got here because this method was fully profiled in the interpreter.
  15.328 +      next_level = CompLevel_full_optimization;
  15.329 +    } else {
  15.330 +      methodDataOop mdo = method->method_data();
  15.331 +      if (mdo != NULL) {
  15.332 +        if (mdo->would_profile()) {
  15.333 +          if (CompileBroker::queue_size(CompLevel_full_optimization) <=
  15.334 +              Tier3DelayOff * compiler_count(CompLevel_full_optimization) &&
  15.335 +              (this->*p)(i, b, cur_level)) {
  15.336 +            next_level = CompLevel_full_profile;
  15.337 +          }
  15.338 +        } else {
  15.339 +          next_level = CompLevel_full_optimization;
  15.340 +        }
  15.341 +      }
  15.342 +    }
  15.343 +    break;
  15.344 +  case CompLevel_full_profile:
  15.345 +    {
  15.346 +      methodDataOop mdo = method->method_data();
  15.347 +      if (mdo != NULL) {
  15.348 +        if (mdo->would_profile()) {
  15.349 +          int mdo_i = mdo->invocation_count_delta();
  15.350 +          int mdo_b = mdo->backedge_count_delta();
  15.351 +          if ((this->*p)(mdo_i, mdo_b, cur_level)) {
  15.352 +            next_level = CompLevel_full_optimization;
  15.353 +          }
  15.354 +        } else {
  15.355 +          next_level = CompLevel_full_optimization;
  15.356 +        }
  15.357 +      }
  15.358 +    }
  15.359 +    break;
  15.360 +  }
  15.361 +  return next_level;
  15.362 +}
  15.363 +
  15.364 +// Determine if a method should be compiled with a normal entry point at a different level.
  15.365 +CompLevel AdvancedThresholdPolicy::call_event(methodOop method,  CompLevel cur_level) {
  15.366 +  CompLevel osr_level = (CompLevel) method->highest_osr_comp_level();
  15.367 +  CompLevel next_level = common(&AdvancedThresholdPolicy::call_predicate, method, cur_level);
  15.368 +
  15.369 +  // If OSR method level is greater than the regular method level, the levels should be
  15.370 +  // equalized by raising the regular method level in order to avoid OSRs during each
  15.371 +  // invocation of the method.
  15.372 +  if (osr_level == CompLevel_full_optimization && cur_level == CompLevel_full_profile) {
  15.373 +    methodDataOop mdo = method->method_data();
  15.374 +    guarantee(mdo != NULL, "MDO should not be NULL");
  15.375 +    if (mdo->invocation_count() >= 1) {
  15.376 +      next_level = CompLevel_full_optimization;
  15.377 +    }
  15.378 +  } else {
  15.379 +    next_level = MAX2(osr_level, next_level);
  15.380 +  }
  15.381 +
  15.382 +  return next_level;
  15.383 +}
  15.384 +
  15.385 +// Determine if we should do an OSR compilation of a given method.
  15.386 +CompLevel AdvancedThresholdPolicy::loop_event(methodOop method, CompLevel cur_level) {
  15.387 +  if (cur_level == CompLevel_none) {
  15.388 +    // If there is a live OSR method that means that we deopted to the interpreter
  15.389 +    // for the transition.
  15.390 +    CompLevel osr_level = (CompLevel)method->highest_osr_comp_level();
  15.391 +    if (osr_level > CompLevel_none) {
  15.392 +      return osr_level;
  15.393 +    }
  15.394 +  }
  15.395 +  return common(&AdvancedThresholdPolicy::loop_predicate, method, cur_level);
  15.396 +}
  15.397 +
  15.398 +// Update the rate and submit compile
  15.399 +void AdvancedThresholdPolicy::submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS) {
  15.400 +  int hot_count = (bci == InvocationEntryBci) ? mh->invocation_count() : mh->backedge_count();
  15.401 +  update_rate(os::javaTimeMillis(), mh());
  15.402 +  CompileBroker::compile_method(mh, bci, level, mh, hot_count, "tiered", THREAD);
  15.403 +}
  15.404 +
  15.405 +
  15.406 +// Handle the invocation event.
  15.407 +void AdvancedThresholdPolicy::method_invocation_event(methodHandle mh, methodHandle imh,
  15.408 +                                                      CompLevel level, TRAPS) {
  15.409 +  if (should_create_mdo(mh(), level)) {
  15.410 +    create_mdo(mh, THREAD);
  15.411 +  }
  15.412 +  if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, InvocationEntryBci)) {
  15.413 +    CompLevel next_level = call_event(mh(), level);
  15.414 +    if (next_level != level) {
  15.415 +      compile(mh, InvocationEntryBci, next_level, THREAD);
  15.416 +    }
  15.417 +  }
  15.418 +}
  15.419 +
  15.420 +// Handle the back branch event. Notice that we can compile the method
  15.421 +// with a regular entry from here.
  15.422 +void AdvancedThresholdPolicy::method_back_branch_event(methodHandle mh, methodHandle imh,
  15.423 +                                                       int bci, CompLevel level, TRAPS) {
  15.424 +  if (should_create_mdo(mh(), level)) {
  15.425 +    create_mdo(mh, THREAD);
  15.426 +  }
  15.427 +
  15.428 +  // If the method is already compiling, quickly bail out.
  15.429 +  if (is_compilation_enabled() && !CompileBroker::compilation_is_in_queue(mh, bci)) {
  15.430 +    // Use loop event as an opportinity to also check there's been
  15.431 +    // enough calls.
  15.432 +    CompLevel cur_level = comp_level(mh());
  15.433 +    CompLevel next_level = call_event(mh(), cur_level);
  15.434 +    CompLevel next_osr_level = loop_event(mh(), level);
  15.435 +    if (next_osr_level  == CompLevel_limited_profile) {
  15.436 +      next_osr_level = CompLevel_full_profile; // OSRs are supposed to be for very hot methods.
  15.437 +    }
  15.438 +    next_level = MAX2(next_level,
  15.439 +                      next_osr_level < CompLevel_full_optimization ? next_osr_level : cur_level);
  15.440 +    bool is_compiling = false;
  15.441 +    if (next_level != cur_level) {
  15.442 +      compile(mh, InvocationEntryBci, next_level, THREAD);
  15.443 +      is_compiling = true;
  15.444 +    }
  15.445 +
  15.446 +    // Do the OSR version
  15.447 +    if (!is_compiling && next_osr_level != level) {
  15.448 +      compile(mh, bci, next_osr_level, THREAD);
  15.449 +    }
  15.450 +  }
  15.451 +}
  15.452 +
  15.453 +#endif // TIERED
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/share/vm/runtime/advancedThresholdPolicy.hpp	Fri Mar 11 21:19:15 2011 -0800
    16.3 @@ -0,0 +1,207 @@
    16.4 +/*
    16.5 +* Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved.
    16.6 +* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
    16.7 +*/
    16.8 +
    16.9 +#ifndef SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
   16.10 +#define SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
   16.11 +
   16.12 +#include "runtime/simpleThresholdPolicy.hpp"
   16.13 +
   16.14 +#ifdef TIERED
   16.15 +class CompileTask;
   16.16 +class CompileQueue;
   16.17 +
   16.18 +/*
   16.19 + *  The system supports 5 execution levels:
   16.20 + *  * level 0 - interpreter
   16.21 + *  * level 1 - C1 with full optimization (no profiling)
   16.22 + *  * level 2 - C1 with invocation and backedge counters
   16.23 + *  * level 3 - C1 with full profiling (level 2 + MDO)
   16.24 + *  * level 4 - C2
   16.25 + *
   16.26 + * Levels 0, 2 and 3 periodically notify the runtime about the current value of the counters
   16.27 + * (invocation counters and backedge counters). The frequency of these notifications is
   16.28 + * different at each level. These notifications are used by the policy to decide what transition
   16.29 + * to make.
   16.30 + *
   16.31 + * Execution starts at level 0 (interpreter), then the policy can decide either to compile the
   16.32 + * method at level 3 or level 2. The decision is based on the following factors:
   16.33 + *    1. The length of the C2 queue determines the next level. The observation is that level 2
   16.34 + * is generally faster than level 3 by about 30%, therefore we would want to minimize the time
   16.35 + * a method spends at level 3. We should only spend the time at level 3 that is necessary to get
   16.36 + * adequate profiling. So, if the C2 queue is long enough it is more beneficial to go first to
   16.37 + * level 2, because if we transitioned to level 3 we would be stuck there until our C2 compile
   16.38 + * request makes its way through the long queue. When the load on C2 recedes we are going to
   16.39 + * recompile at level 3 and start gathering profiling information.
   16.40 + *    2. The length of C1 queue is used to dynamically adjust the thresholds, so as to introduce
   16.41 + * additional filtering if the compiler is overloaded. The rationale is that by the time a
   16.42 + * method gets compiled it can become unused, so it doesn't make sense to put too much onto the
   16.43 + * queue.
   16.44 + *
   16.45 + * After profiling is completed at level 3 the transition is made to level 4. Again, the length
   16.46 + * of the C2 queue is used as a feedback to adjust the thresholds.
   16.47 + *
   16.48 + * After the first C1 compile some basic information is determined about the code like the number
   16.49 + * of the blocks and the number of the loops. Based on that it can be decided that a method
   16.50 + * is trivial and compiling it with C1 will yield the same code. In this case the method is
   16.51 + * compiled at level 1 instead of 4.
   16.52 + *
   16.53 + * We also support profiling at level 0. If C1 is slow enough to produce the level 3 version of
   16.54 + * the code and the C2 queue is sufficiently small we can decide to start profiling in the
   16.55 + * interpreter (and continue profiling in the compiled code once the level 3 version arrives).
   16.56 + * If the profiling at level 0 is fully completed before level 3 version is produced, a level 2
   16.57 + * version is compiled instead in order to run faster waiting for a level 4 version.
   16.58 + *
   16.59 + * Compile queues are implemented as priority queues - for each method in the queue we compute
   16.60 + * the event rate (the number of invocation and backedge counter increments per unit of time).
   16.61 + * When getting an element off the queue we pick the one with the largest rate. Maintaining the
   16.62 + * rate also allows us to remove stale methods (the ones that got on the queue but stopped
   16.63 + * being used shortly after that).
   16.64 +*/
   16.65 +
   16.66 +/* Command line options:
   16.67 + * - Tier?InvokeNotifyFreqLog and Tier?BackedgeNotifyFreqLog control the frequency of method
   16.68 + *   invocation and backedge notifications. Basically every n-th invocation or backedge a mutator thread
   16.69 + *   makes a call into the runtime.
   16.70 + *
   16.71 + * - Tier?CompileThreshold, Tier?BackEdgeThreshold, Tier?MinInvocationThreshold control
   16.72 + *   compilation thresholds.
   16.73 + *   Level 2 thresholds are not used and are provided for option-compatibility and potential future use.
   16.74 + *   Other thresholds work as follows:
   16.75 + *
   16.76 + *   Transition from interpreter (level 0) to C1 with full profiling (level 3) happens when
   16.77 + *   the following predicate is true (X is the level):
   16.78 + *
   16.79 + *   i > TierXInvocationThreshold * s || (i > TierXMinInvocationThreshold * s  && i + b > TierXCompileThreshold * s),
   16.80 + *
   16.81 + *   where $i$ is the number of method invocations, $b$ number of backedges and $s$ is the scaling
   16.82 + *   coefficient that will be discussed further.
   16.83 + *   The intuition is to equalize the time that is spend profiling each method.
   16.84 + *   The same predicate is used to control the transition from level 3 to level 4 (C2). It should be
   16.85 + *   noted though that the thresholds are relative. Moreover i and b for the 0->3 transition come
   16.86 + *   from methodOop and for 3->4 transition they come from MDO (since profiled invocations are
   16.87 + *   counted separately).
   16.88 + *
   16.89 + *   OSR transitions are controlled simply with b > TierXBackEdgeThreshold * s predicates.
   16.90 + *
   16.91 + * - Tier?LoadFeedback options are used to automatically scale the predicates described above depending
   16.92 + *   on the compiler load. The scaling coefficients are computed as follows:
   16.93 + *
   16.94 + *   s = queue_size_X / (TierXLoadFeedback * compiler_count_X) + 1,
   16.95 + *
   16.96 + *   where queue_size_X is the current size of the compiler queue of level X, and compiler_count_X
   16.97 + *   is the number of level X compiler threads.
   16.98 + *
   16.99 + *   Basically these parameters describe how many methods should be in the compile queue
  16.100 + *   per compiler thread before the scaling coefficient increases by one.
  16.101 + *
  16.102 + *   This feedback provides the mechanism to automatically control the flow of compilation requests
  16.103 + *   depending on the machine speed, mutator load and other external factors.
  16.104 + *
  16.105 + * - Tier3DelayOn and Tier3DelayOff parameters control another important feedback loop.
  16.106 + *   Consider the following observation: a method compiled with full profiling (level 3)
  16.107 + *   is about 30% slower than a method at level 2 (just invocation and backedge counters, no MDO).
  16.108 + *   Normally, the following transitions will occur: 0->3->4. The problem arises when the C2 queue
  16.109 + *   gets congested and the 3->4 transition is delayed. While the method is the C2 queue it continues
  16.110 + *   executing at level 3 for much longer time than is required by the predicate and at suboptimal speed.
  16.111 + *   The idea is to dynamically change the behavior of the system in such a way that if a substantial
  16.112 + *   load on C2 is detected we would first do the 0->2 transition allowing a method to run faster.
  16.113 + *   And then when the load decreases to allow 2->3 transitions.
  16.114 + *
  16.115 + *   Tier3Delay* parameters control this switching mechanism.
  16.116 + *   Tier3DelayOn is the number of methods in the C2 queue per compiler thread after which the policy
  16.117 + *   no longer does 0->3 transitions but does 0->2 transitions instead.
  16.118 + *   Tier3DelayOff switches the original behavior back when the number of methods in the C2 queue
  16.119 + *   per compiler thread falls below the specified amount.
  16.120 + *   The hysteresis is necessary to avoid jitter.
  16.121 + *
  16.122 + * - TieredCompileTaskTimeout is the amount of time an idle method can spend in the compile queue.
  16.123 + *   Basically, since we use the event rate d(i + b)/dt as a value of priority when selecting a method to
  16.124 + *   compile from the compile queue, we also can detect stale methods for which the rate has been
  16.125 + *   0 for some time in the same iteration. Stale methods can appear in the queue when an application
  16.126 + *   abruptly changes its behavior.
  16.127 + *
  16.128 + * - TieredStopAtLevel, is used mostly for testing. It allows to bypass the policy logic and stick
  16.129 + *   to a given level. For example it's useful to set TieredStopAtLevel = 1 in order to compile everything
  16.130 + *   with pure c1.
  16.131 + *
  16.132 + * - Tier0ProfilingStartPercentage allows the interpreter to start profiling when the inequalities in the
  16.133 + *   0->3 predicate are already exceeded by the given percentage but the level 3 version of the
  16.134 + *   method is still not ready. We can even go directly from level 0 to 4 if c1 doesn't produce a compiled
  16.135 + *   version in time. This reduces the overall transition to level 4 and decreases the startup time.
  16.136 + *   Note that this behavior is also guarded by the Tier3Delay mechanism: when the c2 queue is too long
  16.137 + *   these is not reason to start profiling prematurely.
  16.138 + *
  16.139 + * - TieredRateUpdateMinTime and TieredRateUpdateMaxTime are parameters of the rate computation.
  16.140 + *   Basically, the rate is not computed more frequently than TieredRateUpdateMinTime and is considered
  16.141 + *   to be zero if no events occurred in TieredRateUpdateMaxTime.
  16.142 + */
  16.143 +
  16.144 +
  16.145 +class AdvancedThresholdPolicy : public SimpleThresholdPolicy {
  16.146 +  jlong _start_time;
  16.147 +
  16.148 +  // Call and loop predicates determine whether a transition to a higher compilation
  16.149 +  // level should be performed (pointers to predicate functions are passed to common().
  16.150 +  // Predicates also take compiler load into account.
  16.151 +  typedef bool (AdvancedThresholdPolicy::*Predicate)(int i, int b, CompLevel cur_level);
  16.152 +  bool call_predicate(int i, int b, CompLevel cur_level);
  16.153 +  bool loop_predicate(int i, int b, CompLevel cur_level);
  16.154 +  // Common transition function. Given a predicate determines if a method should transition to another level.
  16.155 +  CompLevel common(Predicate p, methodOop method, CompLevel cur_level);
  16.156 +  // Transition functions.
  16.157 +  // call_event determines if a method should be compiled at a different
  16.158 +  // level with a regular invocation entry.
  16.159 +  CompLevel call_event(methodOop method, CompLevel cur_level);
  16.160 +  // loop_event checks if a method should be OSR compiled at a different
  16.161 +  // level.
  16.162 +  CompLevel loop_event(methodOop method, CompLevel cur_level);
  16.163 +  // Has a method been long around?
  16.164 +  // We don't remove old methods from the compile queue even if they have
  16.165 +  // very low activity (see select_task()).
  16.166 +  inline bool is_old(methodOop method);
  16.167 +  // Was a given method inactive for a given number of milliseconds.
  16.168 +  // If it is, we would remove it from the queue (see select_task()).
  16.169 +  inline bool is_stale(jlong t, jlong timeout, methodOop m);
  16.170 +  // Compute the weight of the method for the compilation scheduling
  16.171 +  inline double weight(methodOop method);
  16.172 +  // Apply heuristics and return true if x should be compiled before y
  16.173 +  inline bool compare_methods(methodOop x, methodOop y);
  16.174 +  // Compute event rate for a given method. The rate is the number of event (invocations + backedges)
  16.175 +  // per millisecond.
  16.176 +  inline void update_rate(jlong t, methodOop m);
  16.177 +  // Compute threshold scaling coefficient
  16.178 +  inline double threshold_scale(CompLevel level, int feedback_k);
  16.179 +  // If a method is old enough and is still in the interpreter we would want to
  16.180 +  // start profiling without waiting for the compiled method to arrive. This function
  16.181 +  // determines whether we should do that.
  16.182 +  inline bool should_create_mdo(methodOop method, CompLevel cur_level);
  16.183 +  // Create MDO if necessary.
  16.184 +  void create_mdo(methodHandle mh, TRAPS);
  16.185 +  // Is method profiled enough?
  16.186 +  bool is_method_profiled(methodOop method);
  16.187 +
  16.188 +protected:
  16.189 +  void print_specific(EventType type, methodHandle mh, methodHandle imh, int bci, CompLevel level);
  16.190 +
  16.191 +  void set_start_time(jlong t) { _start_time = t;    }
  16.192 +  jlong start_time() const     { return _start_time; }
  16.193 +
  16.194 +  // Submit a given method for compilation (and update the rate).
  16.195 +  virtual void submit_compile(methodHandle mh, int bci, CompLevel level, TRAPS);
  16.196 +  // event() from SimpleThresholdPolicy would call these.
  16.197 +  virtual void method_invocation_event(methodHandle method, methodHandle inlinee,
  16.198 +                                       CompLevel level, TRAPS);
  16.199 +  virtual void method_back_branch_event(methodHandle method, methodHandle inlinee,
  16.200 +                                        int bci, CompLevel level, TRAPS);
  16.201 +public:
  16.202 +  AdvancedThresholdPolicy() : _start_time(0) { }
  16.203 +  // Select task is called by CompileBroker. We should return a task or NULL.
  16.204 +  virtual CompileTask* select_task(CompileQueue* compile_queue);
  16.205 +  virtual void initialize();
  16.206 +};
  16.207 +
  16.208 +#endif // TIERED
  16.209 +
  16.210 +#endif // SHARE_VM_RUNTIME_ADVANCEDTHRESHOLDPOLICY_HPP
    17.1 --- a/src/share/vm/runtime/arguments.cpp	Mon Mar 07 16:03:28 2011 -0500
    17.2 +++ b/src/share/vm/runtime/arguments.cpp	Fri Mar 11 21:19:15 2011 -0800
    17.3 @@ -1026,8 +1026,9 @@
    17.4  }
    17.5  
    17.6  void Arguments::set_tiered_flags() {
    17.7 +  // With tiered, set default policy to AdvancedThresholdPolicy, which is 3.
    17.8    if (FLAG_IS_DEFAULT(CompilationPolicyChoice)) {
    17.9 -    FLAG_SET_DEFAULT(CompilationPolicyChoice, 2);
   17.10 +    FLAG_SET_DEFAULT(CompilationPolicyChoice, 3);
   17.11    }
   17.12    if (CompilationPolicyChoice < 2) {
   17.13      vm_exit_during_initialization(
    18.1 --- a/src/share/vm/runtime/compilationPolicy.cpp	Mon Mar 07 16:03:28 2011 -0500
    18.2 +++ b/src/share/vm/runtime/compilationPolicy.cpp	Fri Mar 11 21:19:15 2011 -0800
    18.3 @@ -1,5 +1,5 @@
    18.4  /*
    18.5 - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
    18.6 + * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
    18.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.8   *
    18.9   * This code is free software; you can redistribute it and/or modify it
   18.10 @@ -32,6 +32,7 @@
   18.11  #include "oops/methodOop.hpp"
   18.12  #include "oops/oop.inline.hpp"
   18.13  #include "prims/nativeLookup.hpp"
   18.14 +#include "runtime/advancedThresholdPolicy.hpp"
   18.15  #include "runtime/compilationPolicy.hpp"
   18.16  #include "runtime/frame.hpp"
   18.17  #include "runtime/handles.inline.hpp"
   18.18 @@ -72,8 +73,15 @@
   18.19      Unimplemented();
   18.20  #endif
   18.21      break;
   18.22 +  case 3:
   18.23 +#ifdef TIERED
   18.24 +    CompilationPolicy::set_policy(new AdvancedThresholdPolicy());
   18.25 +#else
   18.26 +    Unimplemented();
   18.27 +#endif
   18.28 +    break;
   18.29    default:
   18.30 -    fatal("CompilationPolicyChoice must be in the range: [0-2]");
   18.31 +    fatal("CompilationPolicyChoice must be in the range: [0-3]");
   18.32    }
   18.33    CompilationPolicy::policy()->initialize();
   18.34  }
    19.1 --- a/src/share/vm/runtime/sweeper.cpp	Mon Mar 07 16:03:28 2011 -0500
    19.2 +++ b/src/share/vm/runtime/sweeper.cpp	Fri Mar 11 21:19:15 2011 -0800
    19.3 @@ -426,9 +426,7 @@
    19.4        tty->vprint(format, ap);
    19.5        va_end(ap);
    19.6      }
    19.7 -    tty->print_cr(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
    19.8 -                  " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
    19.9 -                  CodeCache::nof_blobs(), CodeCache::nof_nmethods(), CodeCache::nof_adapters(), CodeCache::unallocated_capacity());
   19.10 +    CodeCache::log_state(tty); tty->cr();
   19.11    }
   19.12  
   19.13    if (LogCompilation && (xtty != NULL)) {
   19.14 @@ -440,9 +438,7 @@
   19.15        xtty->vprint(format, ap);
   19.16        va_end(ap);
   19.17      }
   19.18 -    xtty->print(" total_blobs='" UINT32_FORMAT "' nmethods='" UINT32_FORMAT "'"
   19.19 -                " adapters='" UINT32_FORMAT "' free_code_cache='" SIZE_FORMAT "'",
   19.20 -                CodeCache::nof_blobs(), CodeCache::nof_nmethods(), CodeCache::nof_adapters(), CodeCache::unallocated_capacity());
   19.21 +    CodeCache::log_state(xtty);
   19.22      xtty->stamp();
   19.23      xtty->end_elem();
   19.24    }

mercurial