< prev index next >

src/hotspot/share/classfile/resolutionErrors.cpp

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
   1 /*
   2  * Copyright (c) 2005, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/resolutionErrors.hpp"

  27 #include "memory/resourceArea.hpp"
  28 #include "oops/oop.inline.hpp"
  29 #include "runtime/handles.inline.hpp"
  30 #include "runtime/safepoint.hpp"
  31 #include "utilities/hashtable.inline.hpp"
  32 
  33 // add new entry to the table
  34 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
  35                                      const constantPoolHandle& pool, int cp_index,
  36                                      Symbol* error, Symbol* message)
  37 {
  38   assert_locked_or_safepoint(SystemDictionary_lock);
  39   assert(!pool.is_null() && error != NULL, "adding NULL obj");
  40 
  41   ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);
  42   add_entry(index, entry);
  43 }
  44 












  45 // find entry in the table
  46 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
  47                                                        const constantPoolHandle& pool, int cp_index)
  48 {
  49   assert_locked_or_safepoint(SystemDictionary_lock);
  50 
  51   for (ResolutionErrorEntry *error_probe = bucket(index);
  52                          error_probe != NULL;
  53                          error_probe = error_probe->next()) {
  54   if (error_probe->hash() == hash && error_probe->pool() == pool()) {
  55       return error_probe;;
  56     }
  57   }
  58   return NULL;
  59 }
  60 
  61 void ResolutionErrorEntry::set_error(Symbol* e) {
  62   assert(e != NULL, "must set a value");
  63   _error = e;

  64   _error->increment_refcount();

  65 }
  66 
  67 void ResolutionErrorEntry::set_message(Symbol* c) {
  68   _message = c;
  69   if (_message != NULL) {
  70     _message->increment_refcount();
  71   }
  72 }
  73 




  74 // create new error entry
  75 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
  76                                                       int cp_index, Symbol* error,
  77                                                       Symbol* message)
  78 {
  79   ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
  80   entry->set_cp_index(cp_index);
  81   entry->set_error(error);
  82   entry->set_message(message);














  83 
  84   return entry;
  85 }
  86 
  87 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
  88   // decrement error refcount
  89   assert(entry->error() != NULL, "error should be set");
  90   entry->error()->decrement_refcount();

  91   if (entry->message() != NULL) {
  92     entry->message()->decrement_refcount();
  93   }



  94   Hashtable<ConstantPool*, mtClass>::free_entry(entry);
  95 }
  96 
  97 
  98 // create resolution error table
  99 ResolutionErrorTable::ResolutionErrorTable(int table_size)
 100     : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
 101 }
 102 
 103 // RedefineClasses support - remove matching entry of a
 104 // constant pool that is going away
 105 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
 106   assert_locked_or_safepoint(SystemDictionary_lock);
 107   for (int i = 0; i < table_size(); i++) {
 108     for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
 109       ResolutionErrorEntry* entry = *p;
 110       assert(entry->pool() != NULL, "resolution error table is corrupt");
 111       if (entry->pool() == c) {
 112         *p = entry->next();
 113         free_entry(entry);


   1 /*
   2  * Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/resolutionErrors.hpp"
  27 #include "memory/allocation.hpp"
  28 #include "memory/resourceArea.hpp"
  29 #include "oops/oop.inline.hpp"
  30 #include "runtime/handles.inline.hpp"
  31 #include "runtime/safepoint.hpp"
  32 #include "utilities/hashtable.inline.hpp"
  33 
  34 // add new entry to the table
  35 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
  36                                      const constantPoolHandle& pool, int cp_index,
  37                                      Symbol* error, Symbol* message)
  38 {
  39   assert_locked_or_safepoint(SystemDictionary_lock);
  40   assert(!pool.is_null() && error != NULL, "adding NULL obj");
  41 
  42   ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, error, message);
  43   add_entry(index, entry);
  44 }
  45 
  46 // add new entry to the table
  47 void ResolutionErrorTable::add_entry(int index, unsigned int hash,
  48                                      const constantPoolHandle& pool, int cp_index,
  49                                      const char* message)
  50 {
  51   assert_locked_or_safepoint(SystemDictionary_lock);
  52   assert(!pool.is_null() && message != NULL, "adding NULL obj");
  53 
  54   ResolutionErrorEntry* entry = new_entry(hash, pool(), cp_index, message);
  55   add_entry(index, entry);
  56 }
  57 
  58 // find entry in the table
  59 ResolutionErrorEntry* ResolutionErrorTable::find_entry(int index, unsigned int hash,
  60                                                        const constantPoolHandle& pool, int cp_index)
  61 {
  62   assert_locked_or_safepoint(SystemDictionary_lock);
  63 
  64   for (ResolutionErrorEntry *error_probe = bucket(index);
  65                          error_probe != NULL;
  66                          error_probe = error_probe->next()) {
  67   if (error_probe->hash() == hash && error_probe->pool() == pool()) {
  68       return error_probe;;
  69     }
  70   }
  71   return NULL;
  72 }
  73 
  74 void ResolutionErrorEntry::set_error(Symbol* e) {

  75   _error = e;
  76   if (_error != NULL) {
  77     _error->increment_refcount();
  78   }
  79 }
  80 
  81 void ResolutionErrorEntry::set_message(Symbol* c) {
  82   _message = c;
  83   if (_message != NULL) {
  84     _message->increment_refcount();
  85   }
  86 }
  87 
  88 void ResolutionErrorEntry::set_nest_host_error(const char* message) {
  89   _nest_host_error = message;
  90 }
  91 
  92 // create new error entry
  93 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
  94                                                       int cp_index, Symbol* error,
  95                                                       Symbol* message)
  96 {
  97   ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
  98   entry->set_cp_index(cp_index);
  99   entry->set_error(error);
 100   entry->set_message(message);
 101   entry->set_nest_host_error(NULL);
 102 
 103   return entry;
 104 }
 105 
 106 // create new nest host error entry
 107 ResolutionErrorEntry* ResolutionErrorTable::new_entry(int hash, ConstantPool* pool,
 108                                                       int cp_index, const char* message)
 109 {
 110   ResolutionErrorEntry* entry = (ResolutionErrorEntry*)Hashtable<ConstantPool*, mtClass>::new_entry(hash, pool);
 111   entry->set_cp_index(cp_index);
 112   entry->set_nest_host_error(message);
 113   entry->set_error(NULL);
 114   entry->set_message(NULL);
 115 
 116   return entry;
 117 }
 118 
 119 void ResolutionErrorTable::free_entry(ResolutionErrorEntry *entry) {
 120   // decrement error refcount
 121   if (entry->error() != NULL) {
 122     entry->error()->decrement_refcount();
 123   }
 124   if (entry->message() != NULL) {
 125     entry->message()->decrement_refcount();
 126   }
 127   if (entry->nest_host_error() != NULL) {
 128     FREE_C_HEAP_ARRAY(char, entry->nest_host_error());
 129   }
 130   Hashtable<ConstantPool*, mtClass>::free_entry(entry);
 131 }
 132 
 133 
 134 // create resolution error table
 135 ResolutionErrorTable::ResolutionErrorTable(int table_size)
 136     : Hashtable<ConstantPool*, mtClass>(table_size, sizeof(ResolutionErrorEntry)) {
 137 }
 138 
 139 // RedefineClasses support - remove matching entry of a
 140 // constant pool that is going away
 141 void ResolutionErrorTable::delete_entry(ConstantPool* c) {
 142   assert_locked_or_safepoint(SystemDictionary_lock);
 143   for (int i = 0; i < table_size(); i++) {
 144     for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
 145       ResolutionErrorEntry* entry = *p;
 146       assert(entry->pool() != NULL, "resolution error table is corrupt");
 147       if (entry->pool() == c) {
 148         *p = entry->next();
 149         free_entry(entry);


< prev index next >