/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_VM_OOPS_KLASSVTABLE_HPP
#define SHARE_VM_OOPS_KLASSVTABLE_HPP
#include "memory/allocation.hpp"
#include "oops/oopsHierarchy.hpp"
#include "runtime/handles.hpp"
#include "utilities/growableArray.hpp"
// A klassVtable abstracts the variable-length vtable that is embedded in instanceKlass
// and arrayKlass. klassVtable objects are used just as convenient transient accessors to the vtable,
// not to actually hold the vtable data.
// Note: the klassVtable should not be accessed before the class has been verified
// (until that point, the vtable is uninitialized).
// Currently a klassVtable contains a direct reference to the vtable data, and is therefore
// not preserved across GCs.
class vtableEntry;
#ifndef PRODUCT
#endif
// Ordering important, so greater_than (>) can be used as an merge operator.
enum AccessType {
acc_private = 0,
};
public:
}
// accessors
inline methodOop unchecked_method_at(int i) const;
inline oop* adr_method_at(int i) const;
// searching; all methods return -1 if not found
// CDS/RedefineClasses support - clear vtables so they can be reinitialized
// at dump time. Clearing gives us an easy way to tell if the vtable has
// already been reinitialized at dump time (see dump.cpp). Vtables can
// be initialized at run time by RedefineClasses so dumping the right order
// is necessary.
void clear_vtable();
bool is_initialized();
// computes vtable length (in words) and the number of miranda methods
TRAPS);
// RedefineClasses() API support:
// If any entry of this vtable points to any of old_methods,
// replace it with the corresponding new_method.
// trace_name_printed is set to true if the current call has
// printed the klass name so that other routines in the adjust_*
// group don't print the klass name.
int methods_length, bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
void dump_vtable();
// Garbage collection
void oop_follow_contents();
void oop_adjust_pointers();
#ifndef SERIALGC
// Parallel Old
#endif // SERIALGC
// Iterators
// Debugging code
protected:
friend class vtableEntry;
private:
static bool needs_new_vtable_entry(methodHandle m, klassOop super, Handle classloader, Symbol* classname, AccessFlags access_flags, TRAPS);
bool update_inherited_vtable(instanceKlass* klass, methodHandle target_method, int super_vtable_len, bool checkconstraints, TRAPS);
instanceKlass* find_transitive_override(instanceKlass* initialsuper, methodHandle target_method, int vtable_index,
// support for miranda methods
bool is_miranda_entry_at(int i);
void fill_in_mirandas(int& initialized);
static void add_new_mirandas_to_list(GrowableArray<methodOop>* list_of_current_mirandas, objArrayOop current_interface_methods, objArrayOop class_methods, klassOop super);
static void get_mirandas(GrowableArray<methodOop>* mirandas, klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
static int get_num_mirandas(klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
inline instanceKlass* ik() const;
};
// private helper class for klassVtable
// description of entry points:
// destination is interpreted:
// from_compiled_code_entry_point -> c2iadapter
// from_interpreter_entry_point -> interpreter entry point
// destination is compiled:
// from_compiled_code_entry_point -> nmethod entry point
// from_interpreter_entry_point -> i2cadapter
public:
// size in words
static int size() {
return sizeof(vtableEntry) / sizeof(HeapWord);
}
private:
friend class klassVtable;
};
}
}
// Allow one past the last entry to be referenced; useful for loop bounds.
}
// --------------------------------------------------------------------------------
class klassItable;
class itableMethodEntry;
private:
int _offset;
public:
static itableMethodEntry* method_entry(klassOop k, int offset) { return (itableMethodEntry*)(((address)k) + offset); }
// Static size and offset accessors
friend class klassItable;
};
private:
public:
// Static size and offset accessors
friend class klassItable;
};
//
// Format of an itable
//
// ---- offset table ---
// klassOop of interface 1 \
// offset to vtable from start of oop / offset table entry
// ...
// klassOop of interface n \
// offset to vtable from start of oop / offset table entry
// --- vtable for interface 1 ---
// methodOop \
// compiler entry point / method table entry
// ...
// methodOop \
// compiler entry point / method table entry
// -- vtable for interface 2 ---
// ...
//
private:
void initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS);
public:
itableOffsetEntry* offset_entry(int i) { assert(0 <= i && i <= _size_offset_table, "index out of bounds");
return &((itableOffsetEntry*)vtable_start())[i]; }
itableMethodEntry* method_entry(int i) { assert(0 <= i && i <= _size_method_table, "index out of bounds");
return &((itableMethodEntry*)method_start())[i]; }
// Initialization
// Updates
void initialize_with_method(methodOop m);
// RedefineClasses() API support:
// if any entry of this itable points to any of old_methods,
// replace it with the corresponding new_method.
// trace_name_printed is set to true if the current call has
// printed the klass name so that other routines in the adjust_*
// group don't print the klass name.
int methods_length, bool * trace_name_printed);
bool check_no_old_or_obsolete_entries();
void dump_itable();
// Garbage collection
void oop_follow_contents();
void oop_adjust_pointers();
#ifndef SERIALGC
// Parallel Old
#endif // SERIALGC
// Iterators
// Setup of itable
// Resolving of method to index
static int compute_itable_index(methodOop m);
// ...and back again:
private:
intptr_t* method_start() const { return vtable_start() + _size_offset_table * itableOffsetEntry::size(); }
// Helper methods
static int calc_itable_size(int num_interfaces, int num_methods) { return (num_interfaces * itableOffsetEntry::size()) + (num_methods * itableMethodEntry::size()); }
// Statistics
static void update_stats(int size) PRODUCT_RETURN NOT_PRODUCT({ _total_classes++; _total_size += size; })
};
#endif // SHARE_VM_OOPS_KLASSVTABLE_HPP