Skip to content

Commit

Permalink
8299326: LinkResolver::resolve_field resolved_klass cannot be null
Browse files Browse the repository at this point in the history
Reviewed-by: iklam, fparain
  • Loading branch information
coleenp committed Jan 4, 2023
1 parent e3035ba commit ccbcea8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
9 changes: 2 additions & 7 deletions src/hotspot/share/interpreter/linkResolver.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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 @@ -814,7 +814,7 @@ static void trace_method_resolution(const char* prefix,
st->print("%s%s, compile-time-class:%s, method:%s, method_holder:%s, access_flags: ",
prefix,
(klass == NULL ? "<NULL>" : klass->internal_name()),
(resolved_klass == NULL ? "<NULL>" : resolved_klass->internal_name()),
resolved_klass->internal_name(),
Method::name_and_sig_as_C_string(resolved_klass,
method->name(),
method->signature()),
Expand Down Expand Up @@ -970,11 +970,6 @@ void LinkResolver::resolve_field(fieldDescriptor& fd,
Symbol* field = link_info.name();
Symbol* sig = link_info.signature();

if (resolved_klass == NULL) {
ResourceMark rm(THREAD);
THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string());
}

// Resolve instance field
Klass* sel_klass = resolved_klass->find_field(field, sig, &fd);
// check if field exists; i.e., if a klass containing the field def has been selected
Expand Down
31 changes: 17 additions & 14 deletions src/hotspot/share/interpreter/linkResolver.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023, 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 @@ -154,26 +154,29 @@ class LinkInfo : public StackObj {
AccessCheck check_access = AccessCheck::required,
LoaderConstraintCheck check_loader_constraints = LoaderConstraintCheck::required,
constantTag tag = JVM_CONSTANT_Invalid) :
_name(name),
_signature(signature), _resolved_klass(resolved_klass), _current_klass(current_klass), _current_method(methodHandle()),
_check_access(check_access == AccessCheck::required),
_check_loader_constraints(check_loader_constraints == LoaderConstraintCheck::required), _tag(tag) {}
_name(name),
_signature(signature),
_resolved_klass(resolved_klass),
_current_klass(current_klass),
_current_method(methodHandle()),
_check_access(check_access == AccessCheck::required),
_check_loader_constraints(check_loader_constraints == LoaderConstraintCheck::required),
_tag(tag) {
assert(_resolved_klass != nullptr, "must always have a resolved_klass");
}

LinkInfo(Klass* resolved_klass, Symbol* name, Symbol* signature, const methodHandle& current_method,
AccessCheck check_access = AccessCheck::required,
LoaderConstraintCheck check_loader_constraints = LoaderConstraintCheck::required,
constantTag tag = JVM_CONSTANT_Invalid) :
_name(name),
_signature(signature), _resolved_klass(resolved_klass), _current_klass(current_method->method_holder()), _current_method(current_method),
_check_access(check_access == AccessCheck::required),
_check_loader_constraints(check_loader_constraints == LoaderConstraintCheck::required), _tag(tag) {}

LinkInfo(resolved_klass, name, signature, current_method->method_holder(), check_access, check_loader_constraints, tag) {
_current_method = current_method;
}

// Case where we just find the method and don't check access against the current class
// Case where we just find the method and don't check access against the current class, used by JavaCalls
LinkInfo(Klass* resolved_klass, Symbol*name, Symbol* signature) :
_name(name),
_signature(signature), _resolved_klass(resolved_klass), _current_klass(NULL), _current_method(methodHandle()),
_check_access(false), _check_loader_constraints(false), _tag(JVM_CONSTANT_Invalid) {}
LinkInfo(resolved_klass, name, signature, nullptr, AccessCheck::skip, LoaderConstraintCheck::skip,
JVM_CONSTANT_Invalid) {}

// accessors
Symbol* name() const { return _name; }
Expand Down

1 comment on commit ccbcea8

@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.