JDK-8068627 : Change _constMethod and _method_counters in hotspot Method class from pointers to 32-bit values
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • Submitted: 2015-01-07
  • Updated: 2015-04-27
  • Resolved: 2015-04-27
Related Reports
Relates :  
Description
The projected savings are on 64-bit only: 8 bytes savings per hotspot Method instance.

When allocating a Method class, also allocate the ConstMethod in a consecutive block in metaspace. This guarantees the distance from the Method to its _constMethod is never larger than 32-bits.
Also, change Method::_method_counters to a 2-level index with a 16bit top and 16bit bottom.

class Method {
private:
  jint      _const_method_offset;
  ConstMethod* constMethod() const             { return (ConstMethod*)(address(this) + _const_method_offset); }
  ushort _method_counter_block;
  ushort _method_counter_index;

  MethodCounters* method_counters() const {
    if (_method_counters_block == 0xffff) {
        return NULL;
    }
    return &(_blocks[_method_counters_block][_method_counter_index]);
  }

  static MethodCounters** _blocks;

   ...
}

Note: in a CDS image, the Method and ConstMethod are allocated from two different regions (RW and RO), so they cannot be allocated consecutively. However, we can make sure that the (SharedReadWriteSize + SharedReadOnlySize) is less than 4GB, so _const_method_offset can still fit in 32 bits. 

Comments
Not worth the risk, closing as WNF.
27-04-2015

MethodCounters will be allocated in multiple blocks. Each block containing a fixed number -- maybe 65536, since the MethodCounters structure is quite small, and os::malloc probably will not commit the entire block immediately. Instead, memory should be committed only on-demand, when individual pages in the block are touched. Each block will maintain a free list. If all existing blocks are full, a new block is allocated and stored at Method::_blocks[n]; When a method is freed, Method::deallocate_contents is called, and we put its method counter (if allocated) back to the free list. Method::_blocks may need to be a growable array. If so, we must grow it only in a safe point.
07-01-2015

Ioi, could you please explain when and how will the MethodCounters block allocated?
07-01-2015