We have a start-up benchmark that shows Klass::vtable() was called 32458 times, and cost about 2~3% of a elapsed time of 720 ms.
klassVtable* Klass::vtable() const {
return new klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
}
Because the THREAD is not known here, in order to allocate from resource, we need to call Thread::current(), which is expensive.
klassVtable is a fixed-size object with only 4 fields. It should be changed to a ValueObj and passed around as a plain old struct:
klassVtable Klass::vtable() const {
return klassVtable(const_cast<Klass*>(this), start_of_vtable(), vtable_length() / vtableEntry::size());
}
A similar optimization can be done to InstanceKlass::itable() to avoid resource allocation there.