Skip to content

Commit

Permalink
8265411: Avoid unnecessary Method::init_intrinsic_id calls
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes, minqi
  • Loading branch information
iklam committed Apr 21, 2021
1 parent a22ad03 commit 739769c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/classfile/classFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5260,7 +5260,7 @@ static void check_methods_for_intrinsics(const InstanceKlass* ik,
if (klass_id != vmSymbolID::NO_SID) {
for (int j = 0; j < methods->length(); ++j) {
Method* method = methods->at(j);
method->init_intrinsic_id();
method->init_intrinsic_id(klass_id);

if (CheckIntrinsics) {
// Check if an intrinsic is defined for method 'method',
Expand Down
40 changes: 40 additions & 0 deletions src/hotspot/share/classfile/vmIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,46 @@ vmIntrinsics::ID vmIntrinsics::find_id_impl(vmSymbolID holder,
#undef VM_INTRINSIC_CASE
}

class vmIntrinsicsLookup {
bool _class_map[vmSymbols::number_of_symbols()];

constexpr int as_index(vmSymbolID id) const {
int index = vmSymbols::as_int(id);
assert(0 <= index && index < int(sizeof(_class_map)), "must be");
return index;
}

constexpr void set_class_map(vmSymbolID id) {
_class_map[as_index(id)] = true;
}

public:
constexpr vmIntrinsicsLookup() : _class_map() {

#define VM_INTRINSIC_CLASS_MAP(id, klass, name, sig, fcode) \
set_class_map(SID_ENUM(klass));

VM_INTRINSICS_DO(VM_INTRINSIC_CLASS_MAP,
VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, VM_ALIAS_IGNORE);
#undef VM_INTRINSIC_CLASS_MAP


// A few slightly irregular cases. See Method::init_intrinsic_id
set_class_map(SID_ENUM(java_lang_StrictMath));
set_class_map(SID_ENUM(java_lang_invoke_MethodHandle));
set_class_map(SID_ENUM(java_lang_invoke_VarHandle));
}

bool class_has_intrinsics(vmSymbolID holder) const {
return _class_map[as_index(holder)];
}
};

constexpr vmIntrinsicsLookup _intrinsics_lookup;

bool vmIntrinsics::class_has_intrinsics(vmSymbolID holder) {
return _intrinsics_lookup.class_has_intrinsics(holder);
}

const char* vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID id, char* buf, int buflen) {
const char* str = name_at(id);
Expand Down
4 changes: 3 additions & 1 deletion src/hotspot/share/classfile/vmIntrinsics.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, 2021, 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 @@ -1141,6 +1141,8 @@ class vmIntrinsics : AllStatic {
static Flags flags_for(ID id);
#endif

static bool class_has_intrinsics(vmSymbolID holder);

static const char* short_name_as_C_string(ID id, char* buf, int size);

// The methods below provide information related to compiling intrinsics.
Expand Down
13 changes: 9 additions & 4 deletions src/hotspot/share/oops/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ methodHandle Method::make_method_handle_intrinsic(vmIntrinsics::ID iid,
assert(MethodHandles::is_signature_polymorphic_name(m->name()), "");
assert(m->signature() == signature, "");
m->compute_from_signature(signature);
m->init_intrinsic_id();
m->init_intrinsic_id(klass_id_for_intrinsics(m->method_holder()));
assert(m->is_method_handle_intrinsic(), "");
#ifdef ASSERT
if (!MethodHandles::is_signature_polymorphic(m->intrinsic_id())) m->print();
Expand Down Expand Up @@ -1558,17 +1558,22 @@ vmSymbolID Method::klass_id_for_intrinsics(const Klass* holder) {

// see if the klass name is well-known:
Symbol* klass_name = ik->name();
return vmSymbols::find_sid(klass_name);
vmSymbolID id = vmSymbols::find_sid(klass_name);
if (id != vmSymbolID::NO_SID && vmIntrinsics::class_has_intrinsics(id)) {
return id;
} else {
return vmSymbolID::NO_SID;
}
}

void Method::init_intrinsic_id() {
void Method::init_intrinsic_id(vmSymbolID klass_id) {
assert(_intrinsic_id == static_cast<int>(vmIntrinsics::_none), "do this just once");
const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte));
assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size");
assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), "");

// the klass name is well-known:
vmSymbolID klass_id = klass_id_for_intrinsics(method_holder());
assert(klass_id == klass_id_for_intrinsics(method_holder()), "must be");
assert(klass_id != vmSymbolID::NO_SID, "caller responsibility");

// ditto for method and signature:
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/oops/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ class Method : public Metadata {
void set_intrinsic_id(vmIntrinsicID id) { _intrinsic_id = (u2) id; }

// Helper routines for intrinsic_id() and vmIntrinsics::method().
void init_intrinsic_id(); // updates from _none if a match
void init_intrinsic_id(vmSymbolID klass_id); // updates from _none if a match
static vmSymbolID klass_id_for_intrinsics(const Klass* holder);

bool caller_sensitive() {
Expand Down

1 comment on commit 739769c

@openjdk-notifier
Copy link

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.