0N/A/*
4185N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#ifndef SHARE_VM_OOPS_KLASSVTABLE_HPP
1879N/A#define SHARE_VM_OOPS_KLASSVTABLE_HPP
1879N/A
1879N/A#include "memory/allocation.hpp"
1879N/A#include "oops/oopsHierarchy.hpp"
1879N/A#include "runtime/handles.hpp"
1879N/A#include "utilities/growableArray.hpp"
1879N/A
0N/A// A klassVtable abstracts the variable-length vtable that is embedded in instanceKlass
0N/A// and arrayKlass. klassVtable objects are used just as convenient transient accessors to the vtable,
0N/A// not to actually hold the vtable data.
0N/A// Note: the klassVtable should not be accessed before the class has been verified
0N/A// (until that point, the vtable is uninitialized).
0N/A
0N/A// Currently a klassVtable contains a direct reference to the vtable data, and is therefore
0N/A// not preserved across GCs.
0N/A
0N/Aclass vtableEntry;
0N/A
0N/Aclass klassVtable : public ResourceObj {
0N/A KlassHandle _klass; // my klass
0N/A int _tableOffset; // offset of start of vtable data within klass
0N/A int _length; // length of vtable (number of entries)
0N/A#ifndef PRODUCT
0N/A int _verify_count; // to make verify faster
0N/A#endif
0N/A
0N/A // Ordering important, so greater_than (>) can be used as an merge operator.
0N/A enum AccessType {
0N/A acc_private = 0,
0N/A acc_package_private = 1,
0N/A acc_publicprotected = 2
0N/A };
0N/A
0N/A public:
0N/A klassVtable(KlassHandle h_klass, void* base, int length) : _klass(h_klass) {
0N/A _tableOffset = (address)base - (address)h_klass(); _length = length;
0N/A }
0N/A
0N/A // accessors
0N/A vtableEntry* table() const { return (vtableEntry*)(address(_klass()) + _tableOffset); }
0N/A KlassHandle klass() const { return _klass; }
0N/A int length() const { return _length; }
0N/A inline methodOop method_at(int i) const;
0N/A inline methodOop unchecked_method_at(int i) const;
0N/A inline oop* adr_method_at(int i) const;
0N/A
0N/A // searching; all methods return -1 if not found
0N/A int index_of(methodOop m) const { return index_of(m, _length); }
2062N/A int index_of_miranda(Symbol* name, Symbol* signature);
0N/A
0N/A void initialize_vtable(bool checkconstraints, TRAPS); // initialize vtable of a new klass
0N/A
2342N/A // CDS/RedefineClasses support - clear vtables so they can be reinitialized
2342N/A // at dump time. Clearing gives us an easy way to tell if the vtable has
2342N/A // already been reinitialized at dump time (see dump.cpp). Vtables can
2342N/A // be initialized at run time by RedefineClasses so dumping the right order
2342N/A // is necessary.
2342N/A void clear_vtable();
2342N/A bool is_initialized();
2342N/A
2342N/A // computes vtable length (in words) and the number of miranda methods
0N/A static void compute_vtable_size_and_num_mirandas(int &vtable_length, int &num_miranda_methods,
0N/A klassOop super, objArrayOop methods,
652N/A AccessFlags class_flags, Handle classloader,
2062N/A Symbol* classname, objArrayOop local_interfaces,
652N/A TRAPS);
0N/A
0N/A // RedefineClasses() API support:
0N/A // If any entry of this vtable points to any of old_methods,
0N/A // replace it with the corresponding new_method.
0N/A // trace_name_printed is set to true if the current call has
0N/A // printed the klass name so that other routines in the adjust_*
0N/A // group don't print the klass name.
0N/A void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
0N/A int methods_length, bool * trace_name_printed);
4185N/A bool check_no_old_or_obsolete_entries();
4185N/A void dump_vtable();
0N/A
0N/A // Garbage collection
0N/A void oop_follow_contents();
0N/A void oop_adjust_pointers();
0N/A
0N/A#ifndef SERIALGC
0N/A // Parallel Old
0N/A void oop_follow_contents(ParCompactionManager* cm);
0N/A void oop_update_pointers(ParCompactionManager* cm);
0N/A#endif // SERIALGC
0N/A
0N/A // Iterators
0N/A void oop_oop_iterate(OopClosure* blk);
0N/A void oop_oop_iterate_m(OopClosure* blk, MemRegion mr);
0N/A
0N/A // Debugging code
0N/A void print() PRODUCT_RETURN;
0N/A void verify(outputStream* st, bool force = false);
0N/A static void print_statistics() PRODUCT_RETURN;
0N/A
0N/A protected:
0N/A friend class vtableEntry;
0N/A private:
652N/A enum { VTABLE_TRANSITIVE_OVERRIDE_VERSION = 51 } ;
0N/A void copy_vtable_to(vtableEntry* start);
0N/A int initialize_from_super(KlassHandle super);
0N/A int index_of(methodOop m, int len) const; // same as index_of, but search only up to len
0N/A void put_method_at(methodOop m, int index);
2062N/A static bool needs_new_vtable_entry(methodHandle m, klassOop super, Handle classloader, Symbol* classname, AccessFlags access_flags, TRAPS);
0N/A
652N/A bool update_inherited_vtable(instanceKlass* klass, methodHandle target_method, int super_vtable_len, bool checkconstraints, TRAPS);
652N/A instanceKlass* find_transitive_override(instanceKlass* initialsuper, methodHandle target_method, int vtable_index,
2062N/A Handle target_loader, Symbol* target_classname, Thread* THREAD);
0N/A
0N/A // support for miranda methods
0N/A bool is_miranda_entry_at(int i);
0N/A void fill_in_mirandas(int& initialized);
0N/A static bool is_miranda(methodOop m, objArrayOop class_methods, klassOop super);
0N/A static void add_new_mirandas_to_list(GrowableArray<methodOop>* list_of_current_mirandas, objArrayOop current_interface_methods, objArrayOop class_methods, klassOop super);
0N/A static void get_mirandas(GrowableArray<methodOop>* mirandas, klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
0N/A static int get_num_mirandas(klassOop super, objArrayOop class_methods, objArrayOop local_interfaces);
0N/A
0N/A
0N/A void verify_against(outputStream* st, klassVtable* vt, int index);
0N/A inline instanceKlass* ik() const;
0N/A};
0N/A
0N/A
0N/A// private helper class for klassVtable
0N/A// description of entry points:
0N/A// destination is interpreted:
0N/A// from_compiled_code_entry_point -> c2iadapter
0N/A// from_interpreter_entry_point -> interpreter entry point
0N/A// destination is compiled:
0N/A// from_compiled_code_entry_point -> nmethod entry point
0N/A// from_interpreter_entry_point -> i2cadapter
0N/Aclass vtableEntry VALUE_OBJ_CLASS_SPEC {
0N/A public:
0N/A // size in words
0N/A static int size() {
0N/A return sizeof(vtableEntry) / sizeof(HeapWord);
0N/A }
0N/A static int method_offset_in_bytes() { return offset_of(vtableEntry, _method); }
0N/A methodOop method() const { return _method; }
0N/A
0N/A private:
0N/A methodOop _method;
0N/A void set(methodOop method) { assert(method != NULL, "use clear"); _method = method; }
0N/A void clear() { _method = NULL; }
0N/A void print() PRODUCT_RETURN;
0N/A void verify(klassVtable* vt, outputStream* st);
0N/A
0N/A friend class klassVtable;
0N/A};
0N/A
0N/A
0N/Ainline methodOop klassVtable::method_at(int i) const {
0N/A assert(i >= 0 && i < _length, "index out of bounds");
0N/A assert(table()[i].method() != NULL, "should not be null");
0N/A assert(oop(table()[i].method())->is_method(), "should be method");
0N/A return table()[i].method();
0N/A}
0N/A
0N/Ainline methodOop klassVtable::unchecked_method_at(int i) const {
0N/A assert(i >= 0 && i < _length, "index out of bounds");
0N/A return table()[i].method();
0N/A}
0N/A
0N/Ainline oop* klassVtable::adr_method_at(int i) const {
0N/A // Allow one past the last entry to be referenced; useful for loop bounds.
0N/A assert(i >= 0 && i <= _length, "index out of bounds");
0N/A return (oop*)(address(table() + i) + vtableEntry::method_offset_in_bytes());
0N/A}
0N/A
0N/A// --------------------------------------------------------------------------------
0N/Aclass klassItable;
0N/Aclass itableMethodEntry;
0N/A
0N/Aclass itableOffsetEntry VALUE_OBJ_CLASS_SPEC {
0N/A private:
0N/A klassOop _interface;
0N/A int _offset;
0N/A public:
0N/A klassOop interface_klass() const { return _interface; }
0N/A int offset() const { return _offset; }
0N/A
0N/A static itableMethodEntry* method_entry(klassOop k, int offset) { return (itableMethodEntry*)(((address)k) + offset); }
0N/A itableMethodEntry* first_method_entry(klassOop k) { return method_entry(k, _offset); }
0N/A
0N/A void initialize(klassOop interf, int offset) { _interface = interf; _offset = offset; }
0N/A
0N/A // Static size and offset accessors
0N/A static int size() { return sizeof(itableOffsetEntry) / HeapWordSize; } // size in words
0N/A static int interface_offset_in_bytes() { return offset_of(itableOffsetEntry, _interface); }
0N/A static int offset_offset_in_bytes() { return offset_of(itableOffsetEntry, _offset); }
0N/A
0N/A friend class klassItable;
0N/A};
0N/A
0N/A
0N/Aclass itableMethodEntry VALUE_OBJ_CLASS_SPEC {
0N/A private:
0N/A methodOop _method;
0N/A
0N/A public:
0N/A methodOop method() const { return _method; }
0N/A
0N/A void clear() { _method = NULL; }
0N/A
0N/A void initialize(methodOop method);
0N/A
0N/A // Static size and offset accessors
0N/A static int size() { return sizeof(itableMethodEntry) / HeapWordSize; } // size in words
0N/A static int method_offset_in_bytes() { return offset_of(itableMethodEntry, _method); }
0N/A
0N/A friend class klassItable;
0N/A};
0N/A
0N/A//
0N/A// Format of an itable
0N/A//
0N/A// ---- offset table ---
0N/A// klassOop of interface 1 \
0N/A// offset to vtable from start of oop / offset table entry
0N/A// ...
0N/A// klassOop of interface n \
0N/A// offset to vtable from start of oop / offset table entry
0N/A// --- vtable for interface 1 ---
0N/A// methodOop \
0N/A// compiler entry point / method table entry
0N/A// ...
0N/A// methodOop \
0N/A// compiler entry point / method table entry
0N/A// -- vtable for interface 2 ---
0N/A// ...
0N/A//
0N/Aclass klassItable : public ResourceObj {
0N/A private:
0N/A instanceKlassHandle _klass; // my klass
0N/A int _table_offset; // offset of start of itable data within klass (in words)
0N/A int _size_offset_table; // size of offset table (in itableOffset entries)
0N/A int _size_method_table; // size of methodtable (in itableMethodEntry entries)
0N/A
0N/A void initialize_itable_for_interface(int method_table_offset, KlassHandle interf_h, bool checkconstraints, TRAPS);
0N/A public:
0N/A klassItable(instanceKlassHandle klass);
0N/A
0N/A itableOffsetEntry* offset_entry(int i) { assert(0 <= i && i <= _size_offset_table, "index out of bounds");
0N/A return &((itableOffsetEntry*)vtable_start())[i]; }
0N/A
0N/A itableMethodEntry* method_entry(int i) { assert(0 <= i && i <= _size_method_table, "index out of bounds");
0N/A return &((itableMethodEntry*)method_start())[i]; }
0N/A
16N/A int size_offset_table() { return _size_offset_table; }
0N/A
0N/A // Initialization
0N/A void initialize_itable(bool checkconstraints, TRAPS);
0N/A
0N/A // Updates
0N/A void initialize_with_method(methodOop m);
0N/A
0N/A // RedefineClasses() API support:
0N/A // if any entry of this itable points to any of old_methods,
0N/A // replace it with the corresponding new_method.
0N/A // trace_name_printed is set to true if the current call has
0N/A // printed the klass name so that other routines in the adjust_*
0N/A // group don't print the klass name.
0N/A void adjust_method_entries(methodOop* old_methods, methodOop* new_methods,
0N/A int methods_length, bool * trace_name_printed);
4185N/A bool check_no_old_or_obsolete_entries();
4185N/A void dump_itable();
0N/A
0N/A // Garbage collection
0N/A void oop_follow_contents();
0N/A void oop_adjust_pointers();
0N/A
0N/A#ifndef SERIALGC
0N/A // Parallel Old
0N/A void oop_follow_contents(ParCompactionManager* cm);
0N/A void oop_update_pointers(ParCompactionManager* cm);
0N/A#endif // SERIALGC
0N/A
0N/A // Iterators
0N/A void oop_oop_iterate(OopClosure* blk);
0N/A void oop_oop_iterate_m(OopClosure* blk, MemRegion mr);
0N/A
0N/A // Setup of itable
0N/A static int compute_itable_size(objArrayHandle transitive_interfaces);
0N/A static void setup_itable_offset_table(instanceKlassHandle klass);
0N/A
0N/A // Resolving of method to index
0N/A static int compute_itable_index(methodOop m);
665N/A // ...and back again:
665N/A static methodOop method_for_itable_index(klassOop klass, int itable_index);
0N/A
0N/A // Debugging/Statistics
0N/A static void print_statistics() PRODUCT_RETURN;
0N/A private:
0N/A intptr_t* vtable_start() const { return ((intptr_t*)_klass()) + _table_offset; }
0N/A intptr_t* method_start() const { return vtable_start() + _size_offset_table * itableOffsetEntry::size(); }
0N/A
0N/A // Helper methods
0N/A static int calc_itable_size(int num_interfaces, int num_methods) { return (num_interfaces * itableOffsetEntry::size()) + (num_methods * itableMethodEntry::size()); }
0N/A
0N/A // Statistics
0N/A NOT_PRODUCT(static int _total_classes;) // Total no. of classes with itables
0N/A NOT_PRODUCT(static long _total_size;) // Total no. of bytes used for itables
0N/A
0N/A static void update_stats(int size) PRODUCT_RETURN NOT_PRODUCT({ _total_classes++; _total_size += size; })
0N/A};
1879N/A
1879N/A#endif // SHARE_VM_OOPS_KLASSVTABLE_HPP