src/hotspot/share/classfile/classFileParser.cpp
changeset 53705 757e9407bafc
parent 53435 ea254e9fc587
child 53728 675dbad7a9b0
equal deleted inserted replaced
53704:ef72c85a0534 53705:757e9407bafc
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
  5737   set_klass(ik);
  5737   set_klass(ik);
  5738 
  5738 
  5739   debug_only(ik->verify();)
  5739   debug_only(ik->verify();)
  5740 }
  5740 }
  5741 
  5741 
       
  5742 void ClassFileParser::update_class_name(Symbol* new_class_name) {
       
  5743   // Decrement the refcount in the old name, since we're clobbering it.
       
  5744   if (_class_name != NULL) {
       
  5745     _class_name->decrement_refcount();
       
  5746   }
       
  5747   _class_name = new_class_name;
       
  5748   // Increment the refcount of the new name.
       
  5749   // Now the ClassFileParser owns this name and will decrement in
       
  5750   // the destructor.
       
  5751   _class_name->increment_refcount();
       
  5752 }
       
  5753 
       
  5754 
  5742 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
  5755 // For an unsafe anonymous class that is in the unnamed package, move it to its host class's
  5743 // package by prepending its host class's package name to its class name and setting
  5756 // package by prepending its host class's package name to its class name and setting
  5744 // its _class_name field.
  5757 // its _class_name field.
  5745 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
  5758 void ClassFileParser::prepend_host_package_name(const InstanceKlass* unsafe_anonymous_host, TRAPS) {
  5746   ResourceMark rm(THREAD);
  5759   ResourceMark rm(THREAD);
  5760     // Append unsafe anonymous class name. The unsafe anonymous class name can contain odd
  5773     // Append unsafe anonymous class name. The unsafe anonymous class name can contain odd
  5761     // characters.  So, do a strncpy instead of using sprintf("%s...").
  5774     // characters.  So, do a strncpy instead of using sprintf("%s...").
  5762     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
  5775     strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len);
  5763 
  5776 
  5764     // Create a symbol and update the anonymous class name.
  5777     // Create a symbol and update the anonymous class name.
  5765     _class_name = SymbolTable::new_symbol(new_anon_name,
  5778     Symbol* new_name = SymbolTable::new_symbol(new_anon_name,
  5766                                           (int)host_pkg_len + 1 + class_name_len,
  5779                                           (int)host_pkg_len + 1 + class_name_len,
  5767                                           CHECK);
  5780                                           CHECK);
       
  5781     update_class_name(new_name);
  5768   }
  5782   }
  5769 }
  5783 }
  5770 
  5784 
  5771 // If the host class and the anonymous class are in the same package then do
  5785 // If the host class and the anonymous class are in the same package then do
  5772 // nothing.  If the anonymous class is in the unnamed package then move it to its
  5786 // nothing.  If the anonymous class is in the unnamed package then move it to its
  5808                                  GrowableArray<Handle>* cp_patches,
  5822                                  GrowableArray<Handle>* cp_patches,
  5809                                  Publicity pub_level,
  5823                                  Publicity pub_level,
  5810                                  TRAPS) :
  5824                                  TRAPS) :
  5811   _stream(stream),
  5825   _stream(stream),
  5812   _requested_name(name),
  5826   _requested_name(name),
       
  5827   _class_name(NULL),
  5813   _loader_data(loader_data),
  5828   _loader_data(loader_data),
  5814   _unsafe_anonymous_host(unsafe_anonymous_host),
  5829   _unsafe_anonymous_host(unsafe_anonymous_host),
  5815   _cp_patches(cp_patches),
  5830   _cp_patches(cp_patches),
  5816   _num_patched_klasses(0),
  5831   _num_patched_klasses(0),
  5817   _max_num_patched_klasses(0),
  5832   _max_num_patched_klasses(0),
  5865   _has_finalizer(false),
  5880   _has_finalizer(false),
  5866   _has_empty_finalizer(false),
  5881   _has_empty_finalizer(false),
  5867   _has_vanilla_constructor(false),
  5882   _has_vanilla_constructor(false),
  5868   _max_bootstrap_specifier_index(-1) {
  5883   _max_bootstrap_specifier_index(-1) {
  5869 
  5884 
  5870   _class_name = name != NULL ? name : vmSymbols::unknown_class_name();
  5885   update_class_name(name != NULL ? name : vmSymbols::unknown_class_name());
  5871 
  5886 
  5872   assert(THREAD->is_Java_thread(), "invariant");
  5887   assert(THREAD->is_Java_thread(), "invariant");
  5873   assert(_loader_data != NULL, "invariant");
  5888   assert(_loader_data != NULL, "invariant");
  5874   assert(stream != NULL, "invariant");
  5889   assert(stream != NULL, "invariant");
  5875   assert(_stream != NULL, "invariant");
  5890   assert(_stream != NULL, "invariant");
  5935   _fields_annotations = _fields_type_annotations = NULL;
  5950   _fields_annotations = _fields_type_annotations = NULL;
  5936 }
  5951 }
  5937 
  5952 
  5938 // Destructor to clean up
  5953 // Destructor to clean up
  5939 ClassFileParser::~ClassFileParser() {
  5954 ClassFileParser::~ClassFileParser() {
       
  5955   _class_name->decrement_refcount();
       
  5956 
  5940   if (_cp != NULL) {
  5957   if (_cp != NULL) {
  5941     MetadataFactory::free_metadata(_loader_data, _cp);
  5958     MetadataFactory::free_metadata(_loader_data, _cp);
  5942   }
  5959   }
  5943   if (_fields != NULL) {
  5960   if (_fields != NULL) {
  5944     MetadataFactory::free_array<u2>(_loader_data, _fields);
  5961     MetadataFactory::free_array<u2>(_loader_data, _fields);
  6090   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
  6107   Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index);
  6091   assert(class_name_in_cp != NULL, "class_name can't be null");
  6108   assert(class_name_in_cp != NULL, "class_name can't be null");
  6092 
  6109 
  6093   // Update _class_name which could be null previously
  6110   // Update _class_name which could be null previously
  6094   // to reflect the name in the constant pool
  6111   // to reflect the name in the constant pool
  6095   _class_name = class_name_in_cp;
  6112   update_class_name(class_name_in_cp);
  6096 
  6113 
  6097   // Don't need to check whether this class name is legal or not.
  6114   // Don't need to check whether this class name is legal or not.
  6098   // It has been checked when constant pool is parsed.
  6115   // It has been checked when constant pool is parsed.
  6099   // However, make sure it is not an array type.
  6116   // However, make sure it is not an array type.
  6100   if (_need_verify) {
  6117   if (_need_verify) {