Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/classfile/placeholders.cpp
32285 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "classfile/placeholders.hpp"26#include "classfile/systemDictionary.hpp"27#include "oops/oop.inline.hpp"28#include "runtime/fieldType.hpp"29#include "utilities/hashtable.inline.hpp"3031// Placeholder methods3233PlaceholderEntry* PlaceholderTable::new_entry(int hash, Symbol* name,34ClassLoaderData* loader_data,35bool havesupername,36Symbol* supername) {37PlaceholderEntry* entry = (PlaceholderEntry*)Hashtable<Symbol*, mtClass>::new_entry(hash, name);38// Hashtable with Symbol* literal must increment and decrement refcount.39name->increment_refcount();40entry->set_loader_data(loader_data);41entry->set_havesupername(havesupername);42entry->set_supername(supername);43entry->set_superThreadQ(NULL);44entry->set_loadInstanceThreadQ(NULL);45entry->set_defineThreadQ(NULL);46entry->set_definer(NULL);47entry->set_instance_klass(NULL);48return entry;49}5051void PlaceholderTable::free_entry(PlaceholderEntry* entry) {52// decrement Symbol refcount here because Hashtable doesn't.53entry->literal()->decrement_refcount();54if (entry->supername() != NULL) entry->supername()->decrement_refcount();55Hashtable<Symbol*, mtClass>::free_entry(entry);56}575859// Placeholder objects represent classes currently being loaded.60// All threads examining the placeholder table must hold the61// SystemDictionary_lock, so we don't need special precautions62// on store ordering here.63void PlaceholderTable::add_entry(int index, unsigned int hash,64Symbol* class_name, ClassLoaderData* loader_data,65bool havesupername, Symbol* supername){66assert_locked_or_safepoint(SystemDictionary_lock);67assert(class_name != NULL, "adding NULL obj");6869// Both readers and writers are locked so it's safe to just70// create the placeholder and insert it in the list without a membar.71PlaceholderEntry* entry = new_entry(hash, class_name, loader_data, havesupername, supername);72add_entry(index, entry);73}747576// Remove a placeholder object.77void PlaceholderTable::remove_entry(int index, unsigned int hash,78Symbol* class_name,79ClassLoaderData* loader_data) {80assert_locked_or_safepoint(SystemDictionary_lock);81PlaceholderEntry** p = bucket_addr(index);82while (*p) {83PlaceholderEntry *probe = *p;84if (probe->hash() == hash && probe->equals(class_name, loader_data)) {85// Delete entry86*p = probe->next();87free_entry(probe);88return;89}90p = probe->next_addr();91}92}9394PlaceholderEntry* PlaceholderTable::get_entry(int index, unsigned int hash,95Symbol* class_name,96ClassLoaderData* loader_data) {97assert_locked_or_safepoint(SystemDictionary_lock);9899for (PlaceholderEntry *place_probe = bucket(index);100place_probe != NULL;101place_probe = place_probe->next()) {102if (place_probe->hash() == hash &&103place_probe->equals(class_name, loader_data)) {104return place_probe;105}106}107return NULL;108}109110Symbol* PlaceholderTable::find_entry(int index, unsigned int hash,111Symbol* class_name,112ClassLoaderData* loader_data) {113PlaceholderEntry* probe = get_entry(index, hash, class_name, loader_data);114return (probe? probe->klassname(): (Symbol*)NULL);115}116117// find_and_add returns probe pointer - old or new118// If no entry exists, add a placeholder entry119// If entry exists, reuse entry120// For both, push SeenThread for classloadAction121// if havesupername: this is used for circularity for instanceklass loading122PlaceholderEntry* PlaceholderTable::find_and_add(int index, unsigned int hash,123Symbol* name,124ClassLoaderData* loader_data,125classloadAction action,126Symbol* supername,127Thread* thread) {128PlaceholderEntry* probe = get_entry(index, hash, name, loader_data);129if (probe == NULL) {130// Nothing found, add place holder131add_entry(index, hash, name, loader_data, (action == LOAD_SUPER), supername);132probe = get_entry(index, hash, name, loader_data);133} else {134if (action == LOAD_SUPER) {135probe->set_havesupername(true);136probe->set_supername(supername);137}138}139if (probe) probe->add_seen_thread(thread, action);140return probe;141}142143144// placeholder is used to track class loading internal states145// placeholder existence now for loading superclass/superinterface146// superthreadQ tracks class circularity, while loading superclass/superinterface147// loadInstanceThreadQ tracks load_instance_class calls148// definer() tracks the single thread that owns define token149// defineThreadQ tracks waiters on defining thread's results150// 1st claimant creates placeholder151// find_and_add adds SeenThread entry for appropriate queue152// All claimants remove SeenThread after completing action153// On removal: if definer and all queues empty, remove entry154// Note: you can be in both placeholders and systemDictionary155// Therefore - must always check SD first156// Ignores the case where entry is not found157void PlaceholderTable::find_and_remove(int index, unsigned int hash,158Symbol* name, ClassLoaderData* loader_data,159classloadAction action,160Thread* thread) {161assert_locked_or_safepoint(SystemDictionary_lock);162PlaceholderEntry *probe = get_entry(index, hash, name, loader_data);163if (probe != NULL) {164probe->remove_seen_thread(thread, action);165// If no other threads using this entry, and this thread is not using this entry for other states166if ((probe->superThreadQ() == NULL) && (probe->loadInstanceThreadQ() == NULL)167&& (probe->defineThreadQ() == NULL) && (probe->definer() == NULL)) {168remove_entry(index, hash, name, loader_data);169}170}171}172173PlaceholderTable::PlaceholderTable(int table_size)174: TwoOopHashtable<Symbol*, mtClass>(table_size, sizeof(PlaceholderEntry)) {175}176177178void PlaceholderTable::classes_do(KlassClosure* f) {179for (int index = 0; index < table_size(); index++) {180for (PlaceholderEntry* probe = bucket(index);181probe != NULL;182probe = probe->next()) {183probe->classes_do(f);184}185}186}187188189void PlaceholderEntry::classes_do(KlassClosure* closure) {190assert(klassname() != NULL, "should have a non-null klass");191if (_instanceKlass != NULL) {192closure->do_klass(instance_klass());193}194}195196// do all entries in the placeholder table197void PlaceholderTable::entries_do(void f(Symbol*)) {198for (int index = 0; index < table_size(); index++) {199for (PlaceholderEntry* probe = bucket(index);200probe != NULL;201probe = probe->next()) {202f(probe->klassname());203}204}205}206207208#ifndef PRODUCT209// Note, doesn't append a cr210void PlaceholderEntry::print() const {211klassname()->print_value();212if (loader_data() != NULL) {213tty->print(", loader ");214loader_data()->print_value();215}216if (supername() != NULL) {217tty->print(", supername ");218supername()->print_value();219}220if (definer() != NULL) {221tty->print(", definer ");222definer()->print_value();223}224if (instance_klass() != NULL) {225tty->print(", InstanceKlass ");226instance_klass()->print_value();227}228tty->print("\n");229tty->print("loadInstanceThreadQ threads:");230loadInstanceThreadQ()->printActionQ();231tty->print("\n");232tty->print("superThreadQ threads:");233superThreadQ()->printActionQ();234tty->print("\n");235tty->print("defineThreadQ threads:");236defineThreadQ()->printActionQ();237tty->print("\n");238}239#endif240241void PlaceholderEntry::verify() const {242guarantee(loader_data() != NULL, "Must have been setup.");243guarantee(loader_data()->class_loader() == NULL || loader_data()->class_loader()->is_instance(),244"checking type of _loader");245guarantee(instance_klass() == NULL246|| instance_klass()->oop_is_instance(),247"checking type of instance_klass result");248}249250void PlaceholderTable::verify() {251int element_count = 0;252for (int pindex = 0; pindex < table_size(); pindex++) {253for (PlaceholderEntry* probe = bucket(pindex);254probe != NULL;255probe = probe->next()) {256probe->verify();257element_count++; // both klasses and place holders count258}259}260guarantee(number_of_entries() == element_count,261"Verify of system dictionary failed");262}263264265#ifndef PRODUCT266void PlaceholderTable::print() {267for (int pindex = 0; pindex < table_size(); pindex++) {268for (PlaceholderEntry* probe = bucket(pindex);269probe != NULL;270probe = probe->next()) {271if (Verbose) tty->print("%4d: ", pindex);272tty->print(" place holder ");273274probe->print();275tty->cr();276}277}278}279#endif280281282