Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253402: Convert vmSymbols::SID to enum class
Reviewed-by: kvn, coleenp, kbarrett, iveresov
  • Loading branch information
iklam committed Oct 15, 2020
1 parent 038f58d commit 7e5eb49
Show file tree
Hide file tree
Showing 29 changed files with 654 additions and 320 deletions.
33 changes: 17 additions & 16 deletions src/hotspot/share/ci/ciObjectFactory.cpp
Expand Up @@ -67,7 +67,7 @@
// sort of balanced binary tree.

GrowableArray<ciMetadata*>* ciObjectFactory::_shared_ci_metadata = NULL;
ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::SID_LIMIT];
ciSymbol* ciObjectFactory::_shared_ci_symbols[vmSymbols::number_of_symbols()];
int ciObjectFactory::_shared_ident_limit = 0;
volatile bool ciObjectFactory::_initialized = false;

Expand Down Expand Up @@ -126,18 +126,19 @@ void ciObjectFactory::init_shared_objects() {

{
// Create the shared symbols, but not in _shared_ci_metadata.
int i;
for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
assert(vmSymbols::find_sid(vmsym) == i, "1-1 mapping");
ciSymbol* sym = new (_arena) ciSymbol(vmsym, (vmSymbols::SID) i);
for (vmSymbolsIterator it = vmSymbolsRange.begin(); it != vmSymbolsRange.end(); ++it) {
vmSymbolID index = *it;
Symbol* vmsym = vmSymbols::symbol_at(index);
assert(vmSymbols::find_sid(vmsym) == index, "1-1 mapping");
ciSymbol* sym = new (_arena) ciSymbol(vmsym, index);
init_ident_of(sym);
_shared_ci_symbols[i] = sym;
_shared_ci_symbols[vmSymbols::as_int(index)] = sym;
}
#ifdef ASSERT
for (i = vmSymbols::FIRST_SID; i < vmSymbols::SID_LIMIT; i++) {
Symbol* vmsym = vmSymbols::symbol_at((vmSymbols::SID) i);
ciSymbol* sym = vm_symbol_at((vmSymbols::SID) i);
for (vmSymbolsIterator it = vmSymbolsRange.begin(); it != vmSymbolsRange.end(); ++it) {
vmSymbolID index = *it;
Symbol* vmsym = vmSymbols::symbol_at(index);
ciSymbol* sym = vm_symbol_at(index);
assert(sym->get_symbol() == vmsym, "oop must match");
}
assert(ciSymbol::void_class_signature()->get_symbol() == vmSymbols::void_class_signature(), "spot check");
Expand Down Expand Up @@ -208,14 +209,14 @@ void ciObjectFactory::init_shared_objects() {


ciSymbol* ciObjectFactory::get_symbol(Symbol* key) {
vmSymbols::SID sid = vmSymbols::find_sid(key);
if (sid != vmSymbols::NO_SID) {
vmSymbolID sid = vmSymbols::find_sid(key);
if (sid != vmSymbolID::NO_SID) {
// do not pollute the main cache with it
return vm_symbol_at(sid);
}

assert(vmSymbols::find_sid(key) == vmSymbols::NO_SID, "");
ciSymbol* s = new (arena()) ciSymbol(key, vmSymbols::NO_SID);
assert(vmSymbols::find_sid(key) == vmSymbolID::NO_SID, "");
ciSymbol* s = new (arena()) ciSymbol(key, vmSymbolID::NO_SID);
_symbols->push(s);
return s;
}
Expand Down Expand Up @@ -678,8 +679,8 @@ void ciObjectFactory::insert_non_perm(ciObjectFactory::NonPermObject* &where, oo
// ------------------------------------------------------------------
// ciObjectFactory::vm_symbol_at
// Get the ciSymbol corresponding to some index in vmSymbols.
ciSymbol* ciObjectFactory::vm_symbol_at(int index) {
assert(index >= vmSymbols::FIRST_SID && index < vmSymbols::SID_LIMIT, "oob");
ciSymbol* ciObjectFactory::vm_symbol_at(vmSymbolID sid) {
int index = vmSymbols::as_int(sid);
return _shared_ci_symbols[index];
}

Expand Down
5 changes: 3 additions & 2 deletions src/hotspot/share/ci/ciObjectFactory.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,6 +28,7 @@
#include "ci/ciClassList.hpp"
#include "ci/ciObject.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/vmEnums.hpp"

// ciObjectFactory
//
Expand Down Expand Up @@ -104,7 +105,7 @@ class ciObjectFactory : public ResourceObj {
ciSymbol* get_symbol(Symbol* key);

// Get the ciSymbol corresponding to one of the vmSymbols.
static ciSymbol* vm_symbol_at(int index);
static ciSymbol* vm_symbol_at(vmSymbolID index);

// Get the ciMethod representing an unloaded/unfound method.
ciMethod* get_unloaded_method(ciInstanceKlass* holder,
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/ci/ciSymbol.cpp
Expand Up @@ -33,7 +33,7 @@
// ciSymbol::ciSymbol
//
// Preallocated symbol variant. Used with symbols from vmSymbols.
ciSymbol::ciSymbol(Symbol* s, vmSymbols::SID sid)
ciSymbol::ciSymbol(Symbol* s, vmSymbolID sid)
: _symbol(s), _sid(sid)
{
assert(_symbol != NULL, "adding null symbol");
Expand All @@ -43,7 +43,7 @@ ciSymbol::ciSymbol(Symbol* s, vmSymbols::SID sid)

// Normal case for non-famous symbols.
ciSymbol::ciSymbol(Symbol* s)
: _symbol(s), _sid(vmSymbols::NO_SID)
: _symbol(s), _sid(vmSymbolID::NO_SID)
{
assert(_symbol != NULL, "adding null symbol");
_symbol->increment_refcount(); // increment ref count
Expand Down
11 changes: 6 additions & 5 deletions src/hotspot/share/ci/ciSymbol.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,6 +30,7 @@
#include "ci/ciObjectFactory.hpp"
#include "classfile/vmSymbols.hpp"
#include "oops/symbol.hpp"
#include "utilities/vmEnums.hpp"

// ciSymbol
//
Expand All @@ -48,11 +49,11 @@ class ciSymbol : public ciBaseObject {
friend class ciObjArrayKlass;

private:
const vmSymbols::SID _sid;
const vmSymbolID _sid;
DEBUG_ONLY( bool sid_ok() { return vmSymbols::find_sid(get_symbol()) == _sid; } )

ciSymbol(Symbol* s); // normal case, for symbols not mentioned in vmSymbols
ciSymbol(Symbol* s, vmSymbols::SID sid); // for use with vmSymbols
ciSymbol(Symbol* s, vmSymbolID sid); // for use with vmSymbols

Symbol* get_symbol() const { return _symbol; }

Expand All @@ -68,7 +69,7 @@ class ciSymbol : public ciBaseObject {

public:
// The enumeration ID from vmSymbols, or vmSymbols::NO_SID if none.
vmSymbols::SID sid() const { return _sid; }
vmSymbolID sid() const { return _sid; }

// The text of the symbol as a null-terminated utf8 string.
const char* as_utf8();
Expand Down Expand Up @@ -98,7 +99,7 @@ class ciSymbol : public ciBaseObject {
static ciSymbol* make(const char* s);

#define CI_SYMBOL_DECLARE(name, ignore_def) \
static ciSymbol* name() { return ciObjectFactory::vm_symbol_at(vmSymbols::VM_SYMBOL_ENUM_NAME(name)); }
static ciSymbol* name() { return ciObjectFactory::vm_symbol_at(VM_SYMBOL_ENUM_NAME(name)); }
VM_SYMBOLS_DO(CI_SYMBOL_DECLARE, CI_SYMBOL_DECLARE)
#undef CI_SYMBOL_DECLARE

Expand Down
32 changes: 16 additions & 16 deletions src/hotspot/share/classfile/classFileParser.cpp
Expand Up @@ -1742,9 +1742,9 @@ void ClassFileParser::parse_fields(const ClassFileStream* const cfs,

// Injected field
FieldInfo* const field = FieldInfo::from_field_array(fa, index);
field->initialize(JVM_ACC_FIELD_INTERNAL,
injected[n].name_index,
injected[n].signature_index,
field->initialize((u2)JVM_ACC_FIELD_INTERNAL,
(u2)(injected[n].name_index),
(u2)(injected[n].signature_index),
0);

const BasicType type = Signature::basic_type(injected[n].signature());
Expand Down Expand Up @@ -2084,53 +2084,53 @@ AnnotationCollector::ID
AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
const Symbol* name,
const bool can_access_vm_annotations) {
const vmSymbols::SID sid = vmSymbols::find_sid(name);
const vmSymbolID sid = vmSymbols::find_sid(name);
// Privileged code can use all annotations. Other code silently drops some.
const bool privileged = loader_data->is_boot_class_loader_data() ||
loader_data->is_platform_class_loader_data() ||
can_access_vm_annotations;
switch (sid) {
case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
case VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_CallerSensitive;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_ForceInline;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_DontInline;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
case VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_InjectedProfile;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): {
case VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_LambdaForm_Compiled;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Hidden_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Hidden_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_Hidden;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_IntrinsicCandidate_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_IntrinsicCandidate_signature): {
if (_location != _in_method) break; // only allow for methods
if (!privileged) break; // only allow in privileged code
return _method_IntrinsicCandidate;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
if (_location != _in_field) break; // only allow for fields
if (!privileged) break; // only allow in privileged code
return _field_Stable;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
if (_location != _in_field && _location != _in_class) {
break; // only allow for fields and classes
}
Expand All @@ -2139,7 +2139,7 @@ AnnotationCollector::annotation_index(const ClassLoaderData* loader_data,
}
return _jdk_internal_vm_annotation_Contended;
}
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
case VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
if (_location != _in_method) break; // only allow for methods
if (RestrictReservedStack && !privileged) break; // honor privileges
return _jdk_internal_vm_annotation_ReservedStackAccess;
Expand Down Expand Up @@ -5208,9 +5208,9 @@ static void check_methods_for_intrinsics(const InstanceKlass* ik,
// (We used to do this lazily, but now we query it in Rewriter,
// which is eagerly done for every method, so we might as well do it now,
// when everything is fresh in memory.)
const vmSymbols::SID klass_id = Method::klass_id_for_intrinsics(ik);
const vmSymbolID klass_id = Method::klass_id_for_intrinsics(ik);

if (klass_id != vmSymbols::NO_SID) {
if (klass_id != vmSymbolID::NO_SID) {
for (int j = 0; j < methods->length(); ++j) {
Method* method = methods->at(j);
method->init_intrinsic_id();
Expand Down
8 changes: 4 additions & 4 deletions src/hotspot/share/classfile/javaClasses.cpp
Expand Up @@ -85,7 +85,7 @@
#endif

#define DECLARE_INJECTED_FIELD(klass, name, signature, may_be_java) \
{ SystemDictionary::WK_KLASS_ENUM_NAME(klass), vmSymbols::VM_SYMBOL_ENUM_NAME(name##_name), vmSymbols::VM_SYMBOL_ENUM_NAME(signature), may_be_java },
{ SystemDictionary::WK_KLASS_ENUM_NAME(klass), VM_SYMBOL_ENUM_NAME(name##_name), VM_SYMBOL_ENUM_NAME(signature), may_be_java },

InjectedField JavaClasses::_injected_fields[] = {
ALL_INJECTED_FIELDS(DECLARE_INJECTED_FIELD)
Expand Down Expand Up @@ -113,8 +113,8 @@ int JavaClasses::compute_injected_offset(InjectedFieldID id) {
InjectedField* JavaClasses::get_injected(Symbol* class_name, int* field_count) {
*field_count = 0;

vmSymbols::SID sid = vmSymbols::find_sid(class_name);
if (sid == vmSymbols::NO_SID) {
vmSymbolID sid = vmSymbols::find_sid(class_name);
if (sid == vmSymbolID::NO_SID) {
// Only well known classes can inject fields
return NULL;
}
Expand All @@ -123,7 +123,7 @@ InjectedField* JavaClasses::get_injected(Symbol* class_name, int* field_count) {
int start = -1;

#define LOOKUP_INJECTED_FIELD(klass, name, signature, may_be_java) \
if (sid == vmSymbols::VM_SYMBOL_ENUM_NAME(klass)) { \
if (sid == VM_SYMBOL_ENUM_NAME(klass)) { \
count++; \
if (start == -1) start = klass##_##name##_enum; \
}
Expand Down
10 changes: 6 additions & 4 deletions src/hotspot/share/classfile/javaClasses.hpp
Expand Up @@ -29,7 +29,9 @@
#include "jvmtifiles/jvmti.h"
#include "oops/oop.hpp"
#include "oops/instanceKlass.hpp"
#include "oops/symbol.hpp"
#include "runtime/os.hpp"
#include "utilities/vmEnums.hpp"

class RecordComponent;

Expand Down Expand Up @@ -1699,8 +1701,8 @@ class java_lang_InternalError : AllStatic {
class InjectedField {
public:
const SystemDictionary::WKID klass_id;
const vmSymbols::SID name_index;
const vmSymbols::SID signature_index;
const vmSymbolID name_index;
const vmSymbolID signature_index;
const bool may_be_java;


Expand All @@ -1711,8 +1713,8 @@ class InjectedField {
int compute_offset();

// Find the Symbol for this index
static Symbol* lookup_symbol(int symbol_index) {
return vmSymbols::symbol_at((vmSymbols::SID)symbol_index);
static Symbol* lookup_symbol(vmSymbolID symbol_index) {
return Symbol::vm_symbol_at(symbol_index);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/classfile/moduleEntry.hpp
Expand Up @@ -27,7 +27,6 @@

#include "jni.h"
#include "classfile/classLoaderData.hpp"
#include "classfile/vmSymbols.hpp"
#include "oops/oopHandle.hpp"
#include "oops/symbol.hpp"
#include "runtime/jniHandles.hpp"
Expand Down
8 changes: 5 additions & 3 deletions src/hotspot/share/classfile/systemDictionary.cpp
Expand Up @@ -1982,9 +1982,11 @@ void SystemDictionary::initialize(TRAPS) {
}

// Compact table of directions on the initialization of klasses:
// TODO: we should change the base type of vmSymbolID from int to short. Then we can declare this
// array as vmSymbolID wk_init_info[] anf avoid all the type casts.
static const short wk_init_info[] = {
#define WK_KLASS_INIT_INFO(name, symbol) \
((short)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol)),
((short)VM_SYMBOL_ENUM_NAME(symbol)),

WK_KLASSES_DO(WK_KLASS_INIT_INFO)
#undef WK_KLASS_INIT_INFO
Expand All @@ -1995,7 +1997,7 @@ static const short wk_init_info[] = {
bool SystemDictionary::is_well_known_klass(Symbol* class_name) {
int sid;
for (int i = 0; (sid = wk_init_info[i]) != 0; i++) {
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
Symbol* symbol = vmSymbols::symbol_at(vmSymbols::as_SID(sid));
if (class_name == symbol) {
return true;
}
Expand All @@ -2011,7 +2013,7 @@ bool SystemDictionary::is_well_known_klass(Klass* k) {
bool SystemDictionary::resolve_wk_klass(WKID id, TRAPS) {
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
int sid = wk_init_info[id - FIRST_WKID];
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
Symbol* symbol = vmSymbols::symbol_at(vmSymbols::as_SID(sid));
InstanceKlass** klassp = &_well_known_klasses[id];

#if INCLUDE_CDS
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/classfile/systemDictionary.hpp
Expand Up @@ -25,7 +25,6 @@
#ifndef SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP
#define SHARE_CLASSFILE_SYSTEMDICTIONARY_HPP

#include "classfile/vmSymbols.hpp"
#include "oops/oopHandle.hpp"
#include "runtime/handles.hpp"
#include "runtime/signature.hpp"
Expand Down

1 comment on commit 7e5eb49

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 7e5eb49 Oct 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.