Mon, 14 May 2018 09:16:44 -0400
8199226: Improve field accesses
Reviewed-by: acorn, ahgross, rhalade
Contributed-by: harold.seigel@oracle.com
src/share/vm/interpreter/linkResolver.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/interpreter/linkResolver.cpp Tue May 08 15:18:23 2018 -0700 1.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Mon May 14 09:16:44 2018 -0400 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -779,37 +779,37 @@ 1.11 THROW_MSG(vmSymbols::java_lang_NoSuchFieldError(), field->as_C_string()); 1.12 } 1.13 1.14 - if (!check_access) 1.15 - // Access checking may be turned off when calling from within the VM. 1.16 - return; 1.17 + // Access checking may be turned off when calling from within the VM. 1.18 + if (check_access) { 1.19 1.20 - // check access 1.21 - check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); 1.22 + // check access 1.23 + check_field_accessability(current_klass, resolved_klass, sel_klass, fd, CHECK); 1.24 1.25 - // check for errors 1.26 - if (is_static != fd.is_static()) { 1.27 - ResourceMark rm(THREAD); 1.28 - char msg[200]; 1.29 - jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); 1.30 - THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); 1.31 + // check for errors 1.32 + if (is_static != fd.is_static()) { 1.33 + ResourceMark rm(THREAD); 1.34 + char msg[200]; 1.35 + jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); 1.36 + THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); 1.37 + } 1.38 + 1.39 + // Final fields can only be accessed from its own class. 1.40 + if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { 1.41 + THROW(vmSymbols::java_lang_IllegalAccessError()); 1.42 + } 1.43 + 1.44 + // initialize resolved_klass if necessary 1.45 + // note 1: the klass which declared the field must be initialized (i.e, sel_klass) 1.46 + // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) 1.47 + // 1.48 + // note 2: we don't want to force initialization if we are just checking 1.49 + // if the field access is legal; e.g., during compilation 1.50 + if (is_static && initialize_class) { 1.51 + sel_klass->initialize(CHECK); 1.52 + } 1.53 } 1.54 1.55 - // Final fields can only be accessed from its own class. 1.56 - if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { 1.57 - THROW(vmSymbols::java_lang_IllegalAccessError()); 1.58 - } 1.59 - 1.60 - // initialize resolved_klass if necessary 1.61 - // note 1: the klass which declared the field must be initialized (i.e, sel_klass) 1.62 - // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99) 1.63 - // 1.64 - // note 2: we don't want to force initialization if we are just checking 1.65 - // if the field access is legal; e.g., during compilation 1.66 - if (is_static && initialize_class) { 1.67 - sel_klass->initialize(CHECK); 1.68 - } 1.69 - 1.70 - if (sel_klass() != current_klass()) { 1.71 + if (sel_klass() != current_klass() && !current_klass.is_null()) { 1.72 HandleMark hm(THREAD); 1.73 Handle ref_loader (THREAD, InstanceKlass::cast(current_klass())->class_loader()); 1.74 Handle sel_loader (THREAD, InstanceKlass::cast(sel_klass())->class_loader());