From ccbcea830dc8d8b99c919d491adc60f7b4e8f28d Mon Sep 17 00:00:00 2001 From: Coleen Phillimore Date: Wed, 4 Jan 2023 14:42:15 +0000 Subject: [PATCH] 8299326: LinkResolver::resolve_field resolved_klass cannot be null Reviewed-by: iklam, fparain --- .../share/interpreter/linkResolver.cpp | 9 ++---- .../share/interpreter/linkResolver.hpp | 31 ++++++++++--------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/hotspot/share/interpreter/linkResolver.cpp b/src/hotspot/share/interpreter/linkResolver.cpp index db1ed705d13..c62eb622d38 100644 --- a/src/hotspot/share/interpreter/linkResolver.cpp +++ b/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 @@ -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 ? "" : klass->internal_name()), - (resolved_klass == NULL ? "" : resolved_klass->internal_name()), + resolved_klass->internal_name(), Method::name_and_sig_as_C_string(resolved_klass, method->name(), method->signature()), @@ -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 diff --git a/src/hotspot/share/interpreter/linkResolver.hpp b/src/hotspot/share/interpreter/linkResolver.hpp index b1a7274c6bc..9686495c0af 100644 --- a/src/hotspot/share/interpreter/linkResolver.hpp +++ b/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 @@ -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; }