2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2010-11-23 13:22:55 -08:00
|
|
|
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* 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.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/placeholders.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
|
|
|
#include "runtime/fieldType.hpp"
|
|
|
|
#include "utilities/hashtable.inline.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Placeholder methods
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
PlaceholderEntry* PlaceholderTable::new_entry(int hash, Symbol* name,
|
2007-12-01 00:00:00 +00:00
|
|
|
oop loader, bool havesupername,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* supername) {
|
|
|
|
PlaceholderEntry* entry = (PlaceholderEntry*)Hashtable<Symbol*>::new_entry(hash, name);
|
|
|
|
// Hashtable with Symbol* literal must increment and decrement refcount.
|
|
|
|
name->increment_refcount();
|
2007-12-01 00:00:00 +00:00
|
|
|
entry->set_loader(loader);
|
|
|
|
entry->set_havesupername(havesupername);
|
|
|
|
entry->set_supername(supername);
|
|
|
|
entry->set_superThreadQ(NULL);
|
|
|
|
entry->set_loadInstanceThreadQ(NULL);
|
|
|
|
entry->set_defineThreadQ(NULL);
|
|
|
|
entry->set_definer(NULL);
|
|
|
|
entry->set_instanceKlass(NULL);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
void PlaceholderTable::free_entry(PlaceholderEntry* entry) {
|
|
|
|
// decrement Symbol refcount here because Hashtable doesn't.
|
|
|
|
entry->literal()->decrement_refcount();
|
|
|
|
if (entry->supername() != NULL) entry->supername()->decrement_refcount();
|
|
|
|
Hashtable<Symbol*>::free_entry(entry);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Placeholder objects represent classes currently being loaded.
|
|
|
|
// All threads examining the placeholder table must hold the
|
|
|
|
// SystemDictionary_lock, so we don't need special precautions
|
|
|
|
// on store ordering here.
|
|
|
|
void PlaceholderTable::add_entry(int index, unsigned int hash,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name, Handle class_loader,
|
|
|
|
bool havesupername, Symbol* supername){
|
2007-12-01 00:00:00 +00:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(class_name != NULL, "adding NULL obj");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Both readers and writers are locked so it's safe to just
|
|
|
|
// create the placeholder and insert it in the list without a membar.
|
2011-01-27 16:11:27 -08:00
|
|
|
PlaceholderEntry* entry = new_entry(hash, class_name, class_loader(), havesupername, supername);
|
2007-12-01 00:00:00 +00:00
|
|
|
add_entry(index, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Remove a placeholder object.
|
|
|
|
void PlaceholderTable::remove_entry(int index, unsigned int hash,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader) {
|
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
PlaceholderEntry** p = bucket_addr(index);
|
|
|
|
while (*p) {
|
|
|
|
PlaceholderEntry *probe = *p;
|
2011-01-27 16:11:27 -08:00
|
|
|
if (probe->hash() == hash && probe->equals(class_name, class_loader())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// Delete entry
|
|
|
|
*p = probe->next();
|
|
|
|
free_entry(probe);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p = probe->next_addr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader) {
|
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
|
|
|
|
oop class_loader_ = class_loader();
|
|
|
|
|
|
|
|
for (PlaceholderEntry *place_probe = bucket(index);
|
|
|
|
place_probe != NULL;
|
|
|
|
place_probe = place_probe->next()) {
|
|
|
|
if (place_probe->hash() == hash &&
|
2011-01-27 16:11:27 -08:00
|
|
|
place_probe->equals(class_name, class_loader_)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return place_probe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* PlaceholderTable::find_entry(int index, unsigned int hash,
|
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader) {
|
|
|
|
PlaceholderEntry* probe = get_entry(index, hash, class_name, class_loader);
|
2011-01-27 16:11:27 -08:00
|
|
|
return (probe? probe->klassname(): (Symbol*)NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// find_and_add returns probe pointer - old or new
|
|
|
|
// If no entry exists, add a placeholder entry
|
|
|
|
// If entry exists, reuse entry
|
|
|
|
// For both, push SeenThread for classloadAction
|
|
|
|
// if havesupername: this is used for circularity for instanceklass loading
|
2011-01-27 16:11:27 -08:00
|
|
|
PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash, Symbol* name, Handle loader, classloadAction action, Symbol* supername, Thread* thread) {
|
2007-12-01 00:00:00 +00:00
|
|
|
PlaceholderEntry* probe = get_entry(index, hash, name, loader);
|
|
|
|
if (probe == NULL) {
|
|
|
|
// Nothing found, add place holder
|
|
|
|
add_entry(index, hash, name, loader, (action == LOAD_SUPER), supername);
|
|
|
|
probe = get_entry(index, hash, name, loader);
|
|
|
|
} else {
|
|
|
|
if (action == LOAD_SUPER) {
|
|
|
|
probe->set_havesupername(true);
|
2011-01-27 16:11:27 -08:00
|
|
|
probe->set_supername(supername);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (probe) probe->add_seen_thread(thread, action);
|
|
|
|
return probe;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// placeholder used to track class loading internal states
|
|
|
|
// placeholder existence now for loading superclass/superinterface
|
|
|
|
// superthreadQ tracks class circularity, while loading superclass/superinterface
|
|
|
|
// loadInstanceThreadQ tracks load_instance_class calls
|
|
|
|
// definer() tracks the single thread that owns define token
|
|
|
|
// defineThreadQ tracks waiters on defining thread's results
|
|
|
|
// 1st claimant creates placeholder
|
|
|
|
// find_and_add adds SeenThread entry for appropriate queue
|
|
|
|
// All claimants remove SeenThread after completing action
|
|
|
|
// On removal: if definer and all queues empty, remove entry
|
|
|
|
// Note: you can be in both placeholders and systemDictionary
|
|
|
|
// see parse_stream for redefine classes
|
|
|
|
// Therefore - must always check SD first
|
|
|
|
// Ignores the case where entry is not found
|
|
|
|
void PlaceholderTable::find_and_remove(int index, unsigned int hash,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name, Handle loader, Thread* thread) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
PlaceholderEntry *probe = get_entry(index, hash, name, loader);
|
|
|
|
if (probe != NULL) {
|
|
|
|
// No other threads using this entry
|
|
|
|
if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL)
|
|
|
|
&& (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) {
|
|
|
|
remove_entry(index, hash, name, loader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaceholderTable::PlaceholderTable(int table_size)
|
2011-01-27 16:11:27 -08:00
|
|
|
: TwoOopHashtable<Symbol*>(table_size, sizeof(PlaceholderEntry)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlaceholderTable::oops_do(OopClosure* f) {
|
|
|
|
for (int index = 0; index < table_size(); index++) {
|
|
|
|
for (PlaceholderEntry* probe = bucket(index);
|
|
|
|
probe != NULL;
|
|
|
|
probe = probe->next()) {
|
|
|
|
probe->oops_do(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlaceholderEntry::oops_do(OopClosure* blk) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(klassname() != NULL, "should have a non-null klass");
|
2007-12-01 00:00:00 +00:00
|
|
|
if (_loader != NULL) {
|
|
|
|
blk->do_oop(loader_addr());
|
|
|
|
}
|
|
|
|
if (_instanceKlass != NULL) {
|
|
|
|
blk->do_oop((oop*)instanceKlass_addr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// do all entries in the placeholder table
|
2011-01-27 16:11:27 -08:00
|
|
|
void PlaceholderTable::entries_do(void f(Symbol*, oop)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
for (int index = 0; index < table_size(); index++) {
|
|
|
|
for (PlaceholderEntry* probe = bucket(index);
|
|
|
|
probe != NULL;
|
|
|
|
probe = probe->next()) {
|
2011-01-27 16:11:27 -08:00
|
|
|
f(probe->klassname(), probe->loader());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
// Note, doesn't append a cr
|
|
|
|
void PlaceholderEntry::print() const {
|
2011-01-27 16:11:27 -08:00
|
|
|
klassname()->print_value();
|
2007-12-01 00:00:00 +00:00
|
|
|
if (loader() != NULL) {
|
|
|
|
tty->print(", loader ");
|
|
|
|
loader()->print_value();
|
|
|
|
}
|
|
|
|
if (supername() != NULL) {
|
|
|
|
tty->print(", supername ");
|
|
|
|
supername()->print_value();
|
|
|
|
}
|
|
|
|
if (definer() != NULL) {
|
|
|
|
tty->print(", definer ");
|
|
|
|
definer()->print_value();
|
|
|
|
}
|
|
|
|
if (instanceKlass() != NULL) {
|
|
|
|
tty->print(", instanceKlass ");
|
|
|
|
instanceKlass()->print_value();
|
|
|
|
}
|
|
|
|
tty->print("\n");
|
|
|
|
tty->print("loadInstanceThreadQ threads:");
|
|
|
|
loadInstanceThreadQ()->printActionQ();
|
|
|
|
tty->print("\n");
|
|
|
|
tty->print("superThreadQ threads:");
|
|
|
|
superThreadQ()->printActionQ();
|
|
|
|
tty->print("\n");
|
|
|
|
tty->print("defineThreadQ threads:");
|
|
|
|
defineThreadQ()->printActionQ();
|
|
|
|
tty->print("\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void PlaceholderEntry::verify() const {
|
|
|
|
guarantee(loader() == NULL || loader()->is_instance(),
|
|
|
|
"checking type of _loader");
|
|
|
|
guarantee(instanceKlass() == NULL
|
|
|
|
|| Klass::cast(instanceKlass())->oop_is_instance(),
|
|
|
|
"checking type of instanceKlass result");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaceholderTable::verify() {
|
|
|
|
int element_count = 0;
|
|
|
|
for (int pindex = 0; pindex < table_size(); pindex++) {
|
|
|
|
for (PlaceholderEntry* probe = bucket(pindex);
|
|
|
|
probe != NULL;
|
|
|
|
probe = probe->next()) {
|
|
|
|
probe->verify();
|
|
|
|
element_count++; // both klasses and place holders count
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guarantee(number_of_entries() == element_count,
|
|
|
|
"Verify of system dictionary failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
void PlaceholderTable::print() {
|
|
|
|
for (int pindex = 0; pindex < table_size(); pindex++) {
|
|
|
|
for (PlaceholderEntry* probe = bucket(pindex);
|
|
|
|
probe != NULL;
|
|
|
|
probe = probe->next()) {
|
|
|
|
if (Verbose) tty->print("%4d: ", pindex);
|
|
|
|
tty->print(" place holder ");
|
|
|
|
|
|
|
|
probe->print();
|
|
|
|
tty->cr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|