src/hotspot/share/classfile/stringTable.cpp
author stefank
Fri, 23 Mar 2018 18:54:12 +0100
changeset 49594 898ef81cbc0e
parent 49393 93fe2fc5c093
child 49734 f946776e9354
permissions -rw-r--r--
8200106: Move NoSafepointVerifier out from gcLocker.hpp Reviewed-by: coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     1
/*
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 48618
diff changeset
     2
 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     4
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     7
 * published by the Free Software Foundation.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     8
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    13
 * accompanied this code).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    14
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    18
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    21
 * questions.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    22
 *
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    23
 */
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    24
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    25
#include "precompiled.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    26
#include "classfile/altHashing.hpp"
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents: 33628
diff changeset
    27
#include "classfile/compactHashtable.inline.hpp"
35498
392b50de06c6 8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents: 34659
diff changeset
    28
#include "classfile/javaClasses.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    29
#include "classfile/stringTable.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    30
#include "classfile/systemDictionary.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    31
#include "gc/shared/collectedHeap.inline.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 46488
diff changeset
    32
#include "logging/log.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    33
#include "memory/allocation.inline.hpp"
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    34
#include "memory/filemap.hpp"
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    35
#include "memory/metaspaceShared.hpp"
37248
11a660dbbb8e 8132524: Missing includes to resourceArea.hpp
jprovino
parents: 37172
diff changeset
    36
#include "memory/resourceArea.hpp"
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
    37
#include "oops/access.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    38
#include "oops/oop.inline.hpp"
49041
44122f767467 8198286: Direct memory accessors in typeArrayOop.hpp should use Access API
eosterlund
parents: 48618
diff changeset
    39
#include "oops/typeArrayOop.inline.hpp"
40655
9f644073d3a0 8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents: 38647
diff changeset
    40
#include "runtime/atomic.hpp"
49393
93fe2fc5c093 8199472: Fix non-PCH build after JDK-8199319
simonis
parents: 49329
diff changeset
    41
#include "runtime/handles.inline.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    42
#include "runtime/mutexLocker.hpp"
49594
898ef81cbc0e 8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents: 49393
diff changeset
    43
#include "runtime/safepointVerifiers.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46522
diff changeset
    44
#include "services/diagnosticCommand.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    45
#include "utilities/hashtable.inline.hpp"
27684
e0391b2bf625 8064581: Move INCLUDE_ALL_GCS include section to the end of the include list
stefank
parents: 26421
diff changeset
    46
#include "utilities/macros.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    47
#if INCLUDE_ALL_GCS
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
    48
#include "gc/g1/g1CollectedHeap.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29081
diff changeset
    49
#include "gc/g1/g1StringDedup.hpp"
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    50
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    51
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    52
// the number of buckets a thread claims
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    53
const int ClaimChunkSize = 32;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    54
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    55
#ifdef ASSERT
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    56
class StableMemoryChecker : public StackObj {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    57
  enum { _bufsize = wordSize*4 };
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    58
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    59
  address _region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    60
  jint    _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    61
  u1      _save_buf[_bufsize];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    62
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    63
  int sample(u1* save_buf) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    64
    if (_size <= _bufsize) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    65
      memcpy(save_buf, _region, _size);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    66
      return _size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    67
    } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    68
      // copy head and tail
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    69
      memcpy(&save_buf[0],          _region,                      _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    70
      memcpy(&save_buf[_bufsize/2], _region + _size - _bufsize/2, _bufsize/2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    71
      return (_bufsize/2)*2;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    72
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    73
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    74
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    75
 public:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    76
  StableMemoryChecker(const void* region, jint size) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    77
    _region = (address) region;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    78
    _size   = size;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    79
    sample(_save_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    80
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    81
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    82
  bool verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    83
    u1 check_buf[sizeof(_save_buf)];
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    84
    int check_size = sample(check_buf);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    85
    return (0 == memcmp(_save_buf, check_buf, check_size));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    86
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    87
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    88
  void set_region(const void* region) { _region = (address) region; }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    89
};
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    90
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    91
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    92
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    93
// --------------------------------------------------------------------------
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    94
StringTable* StringTable::_the_table = NULL;
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
    95
bool StringTable::_shared_string_mapped = false;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    96
bool StringTable::_needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    97
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    98
volatile int StringTable::_parallel_claimed_idx = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
    99
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   100
CompactHashtable<oop, char> StringTable::_shared_table;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   101
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   102
// Pick hashing algorithm
37172
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   103
unsigned int StringTable::hash_string(const jchar* s, int len) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   104
  return use_alternate_hashcode() ? alt_hash_string(s, len) :
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   105
                                    java_lang_String::hash_code(s, len);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   106
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   107
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   108
unsigned int StringTable::alt_hash_string(const jchar* s, int len) {
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   109
  return AltHashing::murmur3_32(seed(), s, len);
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   110
}
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   111
37172
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   112
unsigned int StringTable::hash_string(oop string) {
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   113
  EXCEPTION_MARK;
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   114
  if (string == NULL) {
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   115
    return hash_string((jchar*)NULL, 0);
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   116
  }
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   117
  ResourceMark rm(THREAD);
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   118
  // All String oops are hashed as unicode
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   119
  int length;
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   120
  jchar* chars = java_lang_String::as_unicode_string(string, length, THREAD);
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   121
  if (chars != NULL) {
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   122
    return hash_string(chars, length);
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   123
  } else {
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   124
    vm_exit_out_of_memory(length, OOM_MALLOC_ERROR, "unable to create Unicode string for verification");
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   125
    return 0;
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   126
  }
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   127
}
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   128
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   129
oop StringTable::string_object(HashtableEntry<oop, mtSymbol>* entry) {
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   130
  return RootAccess<ON_PHANTOM_OOP_REF>::oop_load(entry->literal_addr());
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   131
}
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   132
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   133
oop StringTable::string_object_no_keepalive(HashtableEntry<oop, mtSymbol>* entry) {
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   134
  // The AS_NO_KEEPALIVE peeks at the oop without keeping it alive.
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   135
  // This is *very dangerous* in general but is okay in this specific
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   136
  // case. The subsequent oop_load keeps the oop alive if it it matched
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   137
  // the jchar* string.
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   138
  return RootAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(entry->literal_addr());
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   139
}
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   140
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   141
void StringTable::set_string_object(HashtableEntry<oop, mtSymbol>* entry, oop string) {
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   142
  RootAccess<ON_PHANTOM_OOP_REF>::oop_store(entry->literal_addr(), string);
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   143
}
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   144
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   145
oop StringTable::lookup_shared(jchar* name, int len, unsigned int hash) {
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   146
  assert(hash == java_lang_String::hash_code(name, len),
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   147
         "hash must be computed using java_lang_String::hash_code");
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   148
  return _shared_table.lookup((const char*)name, hash, len);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   149
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   150
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   151
oop StringTable::lookup_in_main_table(int index, jchar* name,
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   152
                                      int len, unsigned int hash) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   153
  int count = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   154
  for (HashtableEntry<oop, mtSymbol>* l = bucket(index); l != NULL; l = l->next()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   155
    count++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   156
    if (l->hash() == hash) {
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   157
      if (java_lang_String::equals(string_object_no_keepalive(l), name, len)) {
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   158
        // We must perform a new load with string_object() that keeps the string
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   159
        // alive as we must expose the oop as strongly reachable when exiting
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   160
        // this context, in case the oop gets published.
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   161
        return string_object(l);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   162
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   163
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   164
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   165
  // If the bucket size is too deep check if this hash code is insufficient.
26421
37d88e604ad0 8056084: Refactor Hashtable to allow implementations without rehashing support
mgerdin
parents: 25492
diff changeset
   166
  if (count >= rehash_count && !needs_rehashing()) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   167
    _needs_rehashing = check_rehash_table(count);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   168
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   169
  return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   170
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   171
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   172
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   173
oop StringTable::basic_add(int index_arg, Handle string, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   174
                           int len, unsigned int hashValue_arg, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   175
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   176
  assert(java_lang_String::equals(string(), name, len),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   177
         "string must be properly initialized");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   178
  // Cannot hit a safepoint in this function because the "this" pointer can move.
35492
c8c0273e6b91 8146690: Make all classes in GC follow the naming convention.
david
parents: 34659
diff changeset
   179
  NoSafepointVerifier nsv;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   180
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   181
  // Check if the symbol table has been rehashed, if so, need to recalculate
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   182
  // the hash value and index before second lookup.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   183
  unsigned int hashValue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   184
  int index;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   185
  if (use_alternate_hashcode()) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   186
    hashValue = alt_hash_string(name, len);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   187
    index = hash_to_index(hashValue);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   188
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   189
    hashValue = hashValue_arg;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   190
    index = index_arg;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   191
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   192
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   193
  // Since look-up was done lock-free, we need to check if another
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   194
  // thread beat us in the race to insert the symbol.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   195
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   196
  // No need to lookup the shared table from here since the caller (intern()) already did
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   197
  oop test = lookup_in_main_table(index, name, len, hashValue); // calls lookup(u1*, int)
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   198
  if (test != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   199
    // Entry already added
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   200
    return test;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   201
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   202
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   203
  HashtableEntry<oop, mtSymbol>* entry = new_entry(hashValue, string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   204
  add_entry(index, entry);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   205
  return string();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   206
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   207
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   208
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   209
oop StringTable::lookup(Symbol* symbol) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   210
  ResourceMark rm;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   211
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   212
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   213
  return lookup(chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   214
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   215
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   216
oop StringTable::lookup(jchar* name, int len) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   217
  // shared table always uses java_lang_String::hash_code
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   218
  unsigned int hash = java_lang_String::hash_code(name, len);
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   219
  oop string = lookup_shared(name, len, hash);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   220
  if (string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   221
    return string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   222
  }
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   223
  if (use_alternate_hashcode()) {
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   224
    hash = alt_hash_string(name, len);
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   225
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   226
  int index = the_table()->hash_to_index(hash);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   227
  string = the_table()->lookup_in_main_table(index, name, len, hash);
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   228
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   229
  return string;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   230
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   231
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   232
oop StringTable::intern(Handle string_or_null, jchar* name,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   233
                        int len, TRAPS) {
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   234
  // shared table always uses java_lang_String::hash_code
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   235
  unsigned int hashValue = java_lang_String::hash_code(name, len);
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   236
  oop found_string = lookup_shared(name, len, hashValue);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   237
  if (found_string != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   238
    return found_string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   239
  }
44323
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   240
  if (use_alternate_hashcode()) {
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   241
    hashValue = alt_hash_string(name, len);
1566bea4793a 8176593: Throwable::getStackTrace performance regression
redestad
parents: 42057
diff changeset
   242
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   243
  int index = the_table()->hash_to_index(hashValue);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   244
  found_string = the_table()->lookup_in_main_table(index, name, len, hashValue);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   245
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   246
  // Found
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   247
  if (found_string != NULL) {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   248
    return found_string;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   249
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   250
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   251
  debug_only(StableMemoryChecker smc(name, len * sizeof(name[0])));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   252
  assert(!Universe::heap()->is_in_reserved(name),
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   253
         "proposed name of symbol must be stable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   254
46271
979ebd346ecf 8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents: 42057
diff changeset
   255
  HandleMark hm(THREAD);  // cleanup strings created
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   256
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   257
  // try to reuse the string if possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   258
  if (!string_or_null.is_null()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   259
    string = string_or_null;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   260
  } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   261
    string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   262
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   263
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   264
#if INCLUDE_ALL_GCS
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   265
  if (G1StringDedup::is_enabled()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   266
    // Deduplicate the string before it is interned. Note that we should never
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   267
    // deduplicate a string after it has been interned. Doing so will counteract
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   268
    // compiler optimizations done on e.g. interned string literals.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   269
    G1StringDedup::deduplicate(string());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   270
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   271
#endif
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   272
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   273
  // Grab the StringTable_lock before getting the_table() because it could
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   274
  // change at safepoint.
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   275
  oop added_or_found;
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   276
  {
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   277
    MutexLocker ml(StringTable_lock, THREAD);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   278
    // Otherwise, add to symbol to table
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   279
    added_or_found = the_table()->basic_add(index, string, name, len,
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   280
                                  hashValue, CHECK_NULL);
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   281
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   282
25492
d27050bdfb04 8049421: G1 Class Unloading after completing a concurrent mark cycle
stefank
parents: 25491
diff changeset
   283
  return added_or_found;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   284
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   285
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   286
oop StringTable::intern(Symbol* symbol, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   287
  if (symbol == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   288
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   289
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   290
  jchar* chars = symbol->as_unicode(length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   291
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   292
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   293
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   294
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   295
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   296
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   297
oop StringTable::intern(oop string, TRAPS)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   298
{
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   299
  if (string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   300
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   301
  int length;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   302
  Handle h_string (THREAD, string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   303
  jchar* chars = java_lang_String::as_unicode_string(string, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   304
  oop result = intern(h_string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   305
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   306
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   307
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   308
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   309
oop StringTable::intern(const char* utf8_string, TRAPS) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   310
  if (utf8_string == NULL) return NULL;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   311
  ResourceMark rm(THREAD);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   312
  int length = UTF8::unicode_length(utf8_string);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   313
  jchar* chars = NEW_RESOURCE_ARRAY(jchar, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   314
  UTF8::convert_to_unicode(utf8_string, chars, length);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   315
  Handle string;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   316
  oop result = intern(string, chars, length, CHECK_NULL);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   317
  return result;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   318
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   319
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   320
void StringTable::unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) {
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   321
  BucketUnlinkContext context;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   322
  buckets_unlink_or_oops_do(is_alive, f, 0, the_table()->table_size(), &context);
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   323
  _the_table->bulk_free_entries(&context);
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   324
  *processed = context._num_processed;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   325
  *removed = context._num_removed;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   326
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   327
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   328
void StringTable::possibly_parallel_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int* processed, int* removed) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   329
  // Readers of the table are unlocked, so we should only be removing
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   330
  // entries at a safepoint.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   331
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   332
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   333
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   334
  BucketUnlinkContext context;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   335
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   336
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   337
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   338
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   339
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   340
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   341
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   342
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   343
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   344
    buckets_unlink_or_oops_do(is_alive, f, start_idx, end_idx, &context);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   345
  }
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   346
  _the_table->bulk_free_entries(&context);
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   347
  *processed = context._num_processed;
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   348
  *removed = context._num_removed;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   349
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   350
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   351
void StringTable::buckets_oops_do(OopClosure* f, int start_idx, int end_idx) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   352
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   353
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   354
  assert(0 <= start_idx && start_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   355
         "start_idx (%d) is out of bounds", start_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   356
  assert(0 <= end_idx && end_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   357
         "end_idx (%d) is out of bounds", end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   358
  assert(start_idx <= end_idx,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   359
         "Index ordering: start_idx=%d, end_idx=%d",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   360
         start_idx, end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   361
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   362
  for (int i = start_idx; i < end_idx; i += 1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   363
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   364
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   365
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   366
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   367
      f->do_oop((oop*)entry->literal_addr());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   368
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   369
      entry = entry->next();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   370
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   371
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   372
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   373
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   374
void StringTable::buckets_unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* f, int start_idx, int end_idx, BucketUnlinkContext* context) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   375
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   376
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   377
  assert(0 <= start_idx && start_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   378
         "start_idx (%d) is out of bounds", start_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   379
  assert(0 <= end_idx && end_idx <= limit,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   380
         "end_idx (%d) is out of bounds", end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   381
  assert(start_idx <= end_idx,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   382
         "Index ordering: start_idx=%d, end_idx=%d",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31345
diff changeset
   383
         start_idx, end_idx);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   384
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   385
  for (int i = start_idx; i < end_idx; ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   386
    HashtableEntry<oop, mtSymbol>** p = the_table()->bucket_addr(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   387
    HashtableEntry<oop, mtSymbol>* entry = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   388
    while (entry != NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   389
      assert(!entry->is_shared(), "CDS not used for the StringTable");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   390
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   391
      if (is_alive->do_object_b(string_object_no_keepalive(entry))) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   392
        if (f != NULL) {
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   393
          f->do_oop(entry->literal_addr());
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   394
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   395
        p = entry->next_addr();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   396
      } else {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   397
        *p = entry->next();
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   398
        context->free_entry(entry);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   399
      }
45114
45644c5f6b8e 8180048: Interned string and symbol table leak memory during parallel unlinking
tschatzl
parents: 44323
diff changeset
   400
      context->_num_processed++;
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   401
      entry = *p;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   402
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   403
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   404
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   405
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   406
void StringTable::oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   407
  buckets_oops_do(f, 0, the_table()->table_size());
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   408
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   409
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   410
void StringTable::possibly_parallel_oops_do(OopClosure* f) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   411
  const int limit = the_table()->table_size();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   412
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   413
  for (;;) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   414
    // Grab next set of buckets to scan
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   415
    int start_idx = Atomic::add(ClaimChunkSize, &_parallel_claimed_idx) - ClaimChunkSize;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   416
    if (start_idx >= limit) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   417
      // End of table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   418
      break;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   419
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   420
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   421
    int end_idx = MIN2(limit, start_idx + ClaimChunkSize);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   422
    buckets_oops_do(f, start_idx, end_idx);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   423
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   424
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   425
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   426
// This verification is part of Universe::verify() and needs to be quick.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   427
// See StringTable::verify_and_compare() below for exhaustive verification.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   428
void StringTable::verify() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   429
  for (int i = 0; i < the_table()->table_size(); ++i) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   430
    HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   431
    for ( ; p != NULL; p = p->next()) {
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   432
      oop s = string_object_no_keepalive(p);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   433
      guarantee(s != NULL, "interned string is NULL");
37172
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   434
      unsigned int h = hash_string(s);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   435
      guarantee(p->hash() == h, "broken hash in string table entry");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   436
      guarantee(the_table()->hash_to_index(h) == i,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   437
                "wrong index in string table");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   438
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   439
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   440
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   441
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   442
void StringTable::dump(outputStream* st, bool verbose) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   443
  if (!verbose) {
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46522
diff changeset
   444
    the_table()->print_table_statistics(st, "StringTable");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   445
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   446
    Thread* THREAD = Thread::current();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   447
    st->print_cr("VERSION: 1.1");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   448
    for (int i = 0; i < the_table()->table_size(); ++i) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   449
      HashtableEntry<oop, mtSymbol>* p = the_table()->bucket(i);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   450
      for ( ; p != NULL; p = p->next()) {
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   451
        oop s = string_object_no_keepalive(p);
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   452
        typeArrayOop value     = java_lang_String::value_no_keepalive(s);
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   453
        int          length    = java_lang_String::length(s);
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   454
        bool         is_latin1 = java_lang_String::is_latin1(s);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   455
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   456
        if (length <= 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   457
          st->print("%d: ", length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   458
        } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   459
          ResourceMark rm(THREAD);
42057
6a5b8ebcd3f2 8164612: NoSuchMethodException when method name contains NULL or Latin-1 supplement character
thartmann
parents: 40655
diff changeset
   460
          int utf8_length = length;
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   461
          char* utf8_string;
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   462
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   463
          if (!is_latin1) {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   464
            jchar* chars = value->char_at_addr(0);
42057
6a5b8ebcd3f2 8164612: NoSuchMethodException when method name contains NULL or Latin-1 supplement character
thartmann
parents: 40655
diff changeset
   465
            utf8_string = UNICODE::as_utf8(chars, utf8_length);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   466
          } else {
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   467
            jbyte* bytes = value->byte_at_addr(0);
42057
6a5b8ebcd3f2 8164612: NoSuchMethodException when method name contains NULL or Latin-1 supplement character
thartmann
parents: 40655
diff changeset
   468
            utf8_string = UNICODE::as_utf8(bytes, utf8_length);
33628
09241459a8b8 8141132: JEP 254: Compact Strings
thartmann
parents: 33148
diff changeset
   469
          }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   470
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   471
          st->print("%d: ", utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   472
          HashtableTextDump::put_utf8(st, utf8_string, utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   473
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   474
        st->cr();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   475
      }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   476
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   477
  }
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   478
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   479
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   480
StringTable::VerifyRetTypes StringTable::compare_entries(
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   481
                                      int bkt1, int e_cnt1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   482
                                      HashtableEntry<oop, mtSymbol>* e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   483
                                      int bkt2, int e_cnt2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   484
                                      HashtableEntry<oop, mtSymbol>* e_ptr2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   485
  // These entries are sanity checked by verify_and_compare_entries()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   486
  // before this function is called.
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   487
  oop str1 = string_object_no_keepalive(e_ptr1);
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   488
  oop str2 = string_object_no_keepalive(e_ptr2);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   489
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   490
  if (str1 == str2) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   491
    tty->print_cr("ERROR: identical oop values (0x" PTR_FORMAT ") "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   492
                  "in entry @ bucket[%d][%d] and entry @ bucket[%d][%d]",
33148
68fa8b6c4340 8042893: compiler: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC needs to be removed from source files
david
parents: 33105
diff changeset
   493
                  p2i(str1), bkt1, e_cnt1, bkt2, e_cnt2);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   494
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   495
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   496
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   497
  if (java_lang_String::equals(str1, str2)) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   498
    tty->print_cr("ERROR: identical String values in entry @ "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   499
                  "bucket[%d][%d] and entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   500
                  bkt1, e_cnt1, bkt2, e_cnt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   501
    return _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   502
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   503
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   504
  return _verify_pass;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   505
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   506
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   507
StringTable::VerifyRetTypes StringTable::verify_entry(int bkt, int e_cnt,
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   508
                                                      HashtableEntry<oop, mtSymbol>* e_ptr,
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   509
                                                      StringTable::VerifyMesgModes mesg_mode) {
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   510
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   511
  VerifyRetTypes ret = _verify_pass;  // be optimistic
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   512
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   513
  oop str = string_object_no_keepalive(e_ptr);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   514
  if (str == NULL) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   515
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   516
      tty->print_cr("ERROR: NULL oop value in entry @ bucket[%d][%d]", bkt,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   517
                    e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   518
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   519
    // NULL oop means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   520
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   521
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   522
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   523
  if (str->klass() != SystemDictionary::String_klass()) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   524
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   525
      tty->print_cr("ERROR: oop is not a String in entry @ bucket[%d][%d]",
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   526
                    bkt, e_cnt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   527
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   528
    // not a String means no more verifications are possible
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   529
    return _verify_fail_done;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   530
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   531
37172
ff4d69314a4c 8144940: Broken hash in string table entry in closed/runtime/7158800/BadUtf8.java
coleenp
parents: 36187
diff changeset
   532
  unsigned int h = hash_string(str);
24426
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   533
  if (e_ptr->hash() != h) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   534
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   535
      tty->print_cr("ERROR: broken hash value in entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   536
                    "bkt_hash=%d, str_hash=%d", bkt, e_cnt, e_ptr->hash(), h);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   537
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   538
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   539
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   540
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   541
  if (the_table()->hash_to_index(h) != bkt) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   542
    if (mesg_mode == _verify_with_mesgs) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   543
      tty->print_cr("ERROR: wrong index value for entry @ bucket[%d][%d], "
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   544
                    "str_hash=%d, hash_to_index=%d", bkt, e_cnt, h,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   545
                    the_table()->hash_to_index(h));
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   546
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   547
    ret = _verify_fail_continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   548
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   549
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   550
  return ret;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   551
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   552
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   553
// See StringTable::verify() above for the quick verification that is
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   554
// part of Universe::verify(). This verification is exhaustive and
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   555
// reports on every issue that is found. StringTable::verify() only
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   556
// reports on the first issue that is found.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   557
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   558
// StringTable::verify_entry() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   559
// - oop value != NULL (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   560
// - oop value is a String
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   561
// - hash(String) == hash in entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   562
// - index for hash == index of entry (same as verify())
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   563
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   564
// StringTable::compare_entries() checks:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   565
// - oops are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   566
// - String values are unique across all entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   567
//
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   568
int StringTable::verify_and_compare_entries() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   569
  assert(StringTable_lock->is_locked(), "sanity check");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   570
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   571
  int  fail_cnt = 0;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   572
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   573
  // first, verify all the entries individually:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   574
  for (int bkt = 0; bkt < the_table()->table_size(); bkt++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   575
    HashtableEntry<oop, mtSymbol>* e_ptr = the_table()->bucket(bkt);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   576
    for (int e_cnt = 0; e_ptr != NULL; e_ptr = e_ptr->next(), e_cnt++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   577
      VerifyRetTypes ret = verify_entry(bkt, e_cnt, e_ptr, _verify_with_mesgs);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   578
      if (ret != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   579
        fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   580
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   581
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   582
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   583
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   584
  // Optimization: if the above check did not find any failures, then
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   585
  // the comparison loop below does not need to call verify_entry()
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   586
  // before calling compare_entries(). If there were failures, then we
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   587
  // have to call verify_entry() to see if the entry can be passed to
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   588
  // compare_entries() safely. When we call verify_entry() in the loop
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   589
  // below, we do so quietly to void duplicate messages and we don't
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   590
  // increment fail_cnt because the failures have already been counted.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   591
  bool need_entry_verify = (fail_cnt != 0);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   592
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   593
  // second, verify all entries relative to each other:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   594
  for (int bkt1 = 0; bkt1 < the_table()->table_size(); bkt1++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   595
    HashtableEntry<oop, mtSymbol>* e_ptr1 = the_table()->bucket(bkt1);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   596
    for (int e_cnt1 = 0; e_ptr1 != NULL; e_ptr1 = e_ptr1->next(), e_cnt1++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   597
      if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   598
        VerifyRetTypes ret = verify_entry(bkt1, e_cnt1, e_ptr1,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   599
                                          _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   600
        if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   601
          // cannot use the current entry to compare against other entries
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   602
          continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   603
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   604
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   605
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   606
      for (int bkt2 = bkt1; bkt2 < the_table()->table_size(); bkt2++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   607
        HashtableEntry<oop, mtSymbol>* e_ptr2 = the_table()->bucket(bkt2);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   608
        int e_cnt2;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   609
        for (e_cnt2 = 0; e_ptr2 != NULL; e_ptr2 = e_ptr2->next(), e_cnt2++) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   610
          if (bkt1 == bkt2 && e_cnt2 <= e_cnt1) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   611
            // skip the entries up to and including the one that
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   612
            // we're comparing against
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   613
            continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   614
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   615
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   616
          if (need_entry_verify) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   617
            VerifyRetTypes ret = verify_entry(bkt2, e_cnt2, e_ptr2,
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   618
                                              _verify_quietly);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   619
            if (ret == _verify_fail_done) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   620
              // cannot compare against this entry
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   621
              continue;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   622
            }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   623
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   624
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   625
          // compare two entries, report and count any failures:
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   626
          if (compare_entries(bkt1, e_cnt1, e_ptr1, bkt2, e_cnt2, e_ptr2)
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   627
              != _verify_pass) {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   628
            fail_cnt++;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   629
          }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   630
        }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   631
      }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   632
    }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   633
  }
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   634
  return fail_cnt;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   635
}
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   636
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   637
// Create a new table and using alternate hash code, populate the new table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   638
// with the existing strings.   Set flag to use the alternate hash code afterwards.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   639
void StringTable::rehash_table() {
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   640
  assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   641
  // This should never happen with -Xshare:dump but it might in testing mode.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   642
  if (DumpSharedSpaces) return;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   643
  StringTable* new_table = new StringTable();
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   644
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   645
  // Rehash the table
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   646
  the_table()->move_to(new_table);
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   647
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   648
  // Delete the table and buckets (entries are reused in new table).
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   649
  delete _the_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   650
  // Don't check if we need rehashing until the table gets unbalanced again.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   651
  // Then rehash with a new global seed.
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   652
  _needs_rehashing = false;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   653
  _the_table = new_table;
0a69c8cdfca9 8038654: Separate SymbolTable and StringTable code
gziemski
parents:
diff changeset
   654
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   655
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   656
// Utility for dumping strings
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   657
StringtableDCmd::StringtableDCmd(outputStream* output, bool heap) :
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   658
                                 DCmdWithParser(output, heap),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   659
  _verbose("-verbose", "Dump the content of each string in the table",
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   660
           "BOOLEAN", false, "false") {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   661
  _dcmdparser.add_dcmd_option(&_verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   662
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   663
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   664
void StringtableDCmd::execute(DCmdSource source, TRAPS) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   665
  VM_DumpHashtable dumper(output(), VM_DumpHashtable::DumpStrings,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   666
                         _verbose.value());
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   667
  VMThread::execute(&dumper);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   668
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   669
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   670
int StringtableDCmd::num_arguments() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   671
  ResourceMark rm;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   672
  StringtableDCmd* dcmd = new StringtableDCmd(NULL, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   673
  if (dcmd != NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   674
    DCmdMark mark(dcmd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   675
    return dcmd->_dcmdparser.num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   676
  } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   677
    return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   678
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents: 27684
diff changeset
   679
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   680
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   681
#if INCLUDE_CDS_JAVA_HEAP
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   682
// Sharing
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   683
oop StringTable::create_archived_string(oop s, Thread* THREAD) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   684
  assert(DumpSharedSpaces, "this function is only used with -Xshare:dump");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   685
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   686
  oop new_s = NULL;
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   687
  typeArrayOop v = java_lang_String::value_no_keepalive(s);
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   688
  typeArrayOop new_v = (typeArrayOop)MetaspaceShared::archive_heap_object(v, THREAD);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   689
  if (new_v == NULL) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   690
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   691
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   692
  new_s = MetaspaceShared::archive_heap_object(s, THREAD);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   693
  if (new_s == NULL) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   694
    return NULL;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   695
  }
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   696
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   697
  // adjust the pointer to the 'value' field in the new String oop
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   698
  java_lang_String::set_value_raw(new_s, new_v);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   699
  return new_s;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   700
}
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   701
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   702
bool StringTable::copy_shared_string(GrowableArray<MemRegion> *string_space,
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   703
                                     CompactStringTableWriter* writer) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   704
  assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   705
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   706
  Thread* THREAD = Thread::current();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   707
  for (int i = 0; i < the_table()->table_size(); ++i) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   708
    HashtableEntry<oop, mtSymbol>* bucket = the_table()->bucket(i);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   709
    for ( ; bucket != NULL; bucket = bucket->next()) {
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   710
      oop s = string_object_no_keepalive(bucket);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   711
      unsigned int hash = java_lang_String::hash_code(s);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   712
      if (hash == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   713
        continue;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   714
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   715
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   716
      java_lang_String::set_hash(s, hash);
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   717
      oop new_s = create_archived_string(s, THREAD);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   718
      if (new_s == NULL) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   719
        continue;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   720
      }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   721
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   722
      // set the archived string in bucket
48618
688e5cbd0b91 8192003: Refactor weak references in StringTable to use the Access API
eosterlund
parents: 47216
diff changeset
   723
      set_string_object(bucket, new_s);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   724
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   725
      // add to the compact table
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   726
      writer->add(hash, new_s);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   727
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   728
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   729
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   730
  return true;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   731
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   732
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   733
void StringTable::write_to_archive(GrowableArray<MemRegion> *string_space) {
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   734
  assert(MetaspaceShared::is_heap_object_archiving_allowed(), "must be");
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   735
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   736
  _shared_table.reset();
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   737
  int num_buckets = the_table()->number_of_entries() /
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   738
                         SharedSymbolTableBucketSize;
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   739
  // calculation of num_buckets can result in zero buckets, we need at least one
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   740
  CompactStringTableWriter writer(num_buckets > 1 ? num_buckets : 1,
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   741
                                  &MetaspaceShared::stats()->string);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   742
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   743
  // Copy the interned strings into the "string space" within the java heap
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   744
  if (copy_shared_string(string_space, &writer)) {
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   745
    writer.dump(&_shared_table);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   746
  }
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   747
}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   748
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   749
void StringTable::serialize(SerializeClosure* soc) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   750
  _shared_table.set_type(CompactHashtable<oop, char>::_string_table);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   751
  _shared_table.serialize(soc);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   752
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   753
  if (soc->writing()) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   754
    _shared_table.reset(); // Sanity. Make sure we don't use the shared table at dump time
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   755
  } else if (!_shared_string_mapped) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 37248
diff changeset
   756
    _shared_table.reset();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   757
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   758
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   759
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   760
void StringTable::shared_oops_do(OopClosure* f) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   761
  _shared_table.oops_do(f);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 30764
diff changeset
   762
}
46810
7dad333205cd 8179302: Pre-resolve constant pool string entries and cache resolved_reference arrays in CDS archive.
jiangli
parents: 46746
diff changeset
   763
#endif //INCLUDE_CDS_JAVA_HEAP