src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/share/vm/interpreter/linkResolver.cpp	Fri Jun 10 17:18:54 2016
--- new/src/share/vm/interpreter/linkResolver.cpp	Fri Jun 10 17:18:54 2016

*** 221,240 **** --- 221,257 ---- #endif //------------------------------------------------------------------------------------------------------------------------ // Implementation of LinkInfo + LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, methodHandle current_method, TRAPS) { + // resolve klass + Klass* result = pool->klass_ref_at(index, CHECK); + _resolved_klass = KlassHandle(THREAD, result); + + // Get name, signature, and static klass + _name = pool->name_ref_at(index); + _signature = pool->signature_ref_at(index); + _tag = pool->tag_ref_at(index); + _current_klass = KlassHandle(THREAD, pool->pool_holder()); + _current_method = current_method; + + // Coming from the constant pool always checks access + _check_access = true; + } + LinkInfo::LinkInfo(const constantPoolHandle& pool, int index, TRAPS) { // resolve klass Klass* result = pool->klass_ref_at(index, CHECK); _resolved_klass = KlassHandle(THREAD, result); // Get name, signature, and static klass _name = pool->name_ref_at(index); _signature = pool->signature_ref_at(index); _tag = pool->tag_ref_at(index); _current_klass = KlassHandle(THREAD, pool->pool_holder()); + _current_method = methodHandle(); // Coming from the constant pool always checks access _check_access = true; }
*** 575,585 **** --- 592,602 ---- KlassHandle current_klass(THREAD, pool->pool_holder()); LinkInfo link_info(resolved_klass, method_name, method_signature, current_klass); return resolve_method(link_info, code, THREAD); } ! LinkInfo link_info(pool, index, methodHandle(), CHECK_NULL); resolved_klass = link_info.resolved_klass(); if (pool->has_preresolution() || (resolved_klass() == SystemDictionary::MethodHandle_klass() && MethodHandles::is_signature_polymorphic_name(resolved_klass(), link_info.name()))) {
*** 873,884 **** --- 890,901 ---- ); return; } } ! void LinkResolver::resolve_field_access(fieldDescriptor& fd, const constantPoolHandle& pool, int index, const methodHandle& method, Bytecodes::Code byte, TRAPS) { ! LinkInfo link_info(pool, index, CHECK); ! LinkInfo link_info(pool, index, method, CHECK); resolve_field(fd, link_info, byte, true, CHECK); } void LinkResolver::resolve_field(fieldDescriptor& fd, const LinkInfo& link_info,
*** 923,935 **** --- 940,983 ---- char msg[200]; jio_snprintf(msg, sizeof(msg), "Expected %s field %s.%s", is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string()); THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), msg); } // Final fields can only be accessed from its own class. if (is_put && fd.access_flags().is_final() && sel_klass() != current_klass()) { THROW(vmSymbols::java_lang_IllegalAccessError()); + // A final field can be modified only + // (1) by methods declared in the class declaring the field and + // (2) by the <clinit> method (in case of a static field) + // or by the <init> method (in case of an instance field). + if (is_put && fd.access_flags().is_final()) { + ResourceMark rm(THREAD); + stringStream ss; + + if (sel_klass() != current_klass()) { + ss.print("Update to %s final field %s.%s attempted from a different class (%s) than the field's declaring class", + is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), + current_klass()->external_name()); + THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); + } + + if (CheckFinalFieldModifications && + fd.constants()->pool_holder()->major_version() >= 53) { + methodHandle m = link_info.current_method(); + assert(!m.is_null(), "information about the current method must be available for 'put' bytecodes"); + bool is_initialized_static_final_update = (byte == Bytecodes::_putstatic && + fd.is_static() && + !m()->is_static_initializer()); + bool is_initialized_instance_final_update = ((byte == Bytecodes::_putfield || byte == Bytecodes::_nofast_putfield) && + !fd.is_static() && + !m->is_object_initializer()); + + if (is_initialized_static_final_update || is_initialized_instance_final_update) { + ss.print("Update to %s final field %s.%s attempted from a different method (%s) than the initializer method %s ", + is_static ? "static" : "non-static", resolved_klass()->external_name(), fd.name()->as_C_string(), + current_klass()->external_name(), + is_static ? "<clinit>" : "<init>"); + THROW_MSG(vmSymbols::java_lang_IllegalAccessError(), ss.as_string()); + } + } } // initialize resolved_klass if necessary // note 1: the klass which declared the field must be initialized (i.e, sel_klass) // according to the newest JVM spec (5.5, p.170) - was bug (gri 7/28/99)

src/share/vm/interpreter/linkResolver.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File