author | mchung |
Tue, 24 Nov 2015 14:59:17 -0800 | |
changeset 34280 | 72bfaaffee36 |
parent 34242 | e530decd7c63 |
child 34659 | 3a7071043457 |
permissions | -rw-r--r-- |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
1 |
/* |
28615
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
4 |
* |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
8 |
* |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
13 |
* accompanied this code). |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
14 |
* |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
18 |
* |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
21 |
* questions. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
22 |
* |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
23 |
*/ |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
24 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
26 |
#include "classfile/javaClasses.hpp" |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
27 |
#include "memory/metaspaceShared.hpp" |
31386
e54c60e0359c
8129446: crash when reporting corrupted classfile
kbarrett
parents:
31345
diff
changeset
|
28 |
#include "prims/jvm.h" |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
29 |
#include "utilities/numberSeq.hpp" |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
30 |
#include <sys/stat.h> |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
31 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
32 |
///////////////////////////////////////////////////// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
33 |
// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
34 |
// The compact hash table writer implementations |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
35 |
// |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
36 |
CompactHashtableWriter::CompactHashtableWriter(int table_type, |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
37 |
int num_entries, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
38 |
CompactHashtableStats* stats) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
39 |
assert(DumpSharedSpaces, "dump-time only"); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
40 |
_type = table_type; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
41 |
_num_entries = num_entries; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
42 |
_num_buckets = number_of_buckets(_num_entries); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
43 |
_buckets = NEW_C_HEAP_ARRAY(Entry*, _num_buckets, mtSymbol); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
44 |
memset(_buckets, 0, sizeof(Entry*) * _num_buckets); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
45 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
46 |
/* bucket sizes table */ |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
47 |
_bucket_sizes = NEW_C_HEAP_ARRAY(juint, _num_buckets, mtSymbol); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
48 |
memset(_bucket_sizes, 0, sizeof(juint) * _num_buckets); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
49 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
50 |
stats->hashentry_count = _num_entries; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
51 |
// Compact buckets' entries will have only the 4-byte offset, but |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
52 |
// we don't know how many there will be at this point. So use a |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
53 |
// conservative estimate here. The size is adjusted later when we |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
54 |
// write out the buckets. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
55 |
stats->hashentry_bytes = _num_entries * 8; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
56 |
stats->bucket_count = _num_buckets; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
57 |
stats->bucket_bytes = (_num_buckets + 1) * (sizeof(juint)); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
58 |
_stats = stats; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
59 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
60 |
// See compactHashtable.hpp for table layout |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
61 |
_required_bytes = sizeof(juint) * 2; // _base_address, written as 2 juints |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
62 |
_required_bytes+= sizeof(juint) + // num_entries |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
63 |
sizeof(juint) + // num_buckets |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
64 |
stats->hashentry_bytes + |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
65 |
stats->bucket_bytes; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
66 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
67 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
68 |
CompactHashtableWriter::~CompactHashtableWriter() { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
69 |
for (int index = 0; index < _num_buckets; index++) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
70 |
Entry* next = NULL; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
71 |
for (Entry* tent = _buckets[index]; tent; tent = next) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
72 |
next = tent->next(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
73 |
delete tent; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
74 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
75 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
76 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
77 |
FREE_C_HEAP_ARRAY(juint, _bucket_sizes); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
78 |
FREE_C_HEAP_ARRAY(Entry*, _buckets); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
79 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
80 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
81 |
// Calculate the number of buckets in the temporary hash table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
82 |
int CompactHashtableWriter::number_of_buckets(int num_entries) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
83 |
const int buksize = (int)SharedSymbolTableBucketSize; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
84 |
int num_buckets = (num_entries + buksize - 1) / buksize; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
85 |
num_buckets = (num_buckets + 1) & (~0x01); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
86 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
87 |
return num_buckets; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
88 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
89 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
90 |
// Add a symbol entry to the temporary hash table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
91 |
void CompactHashtableWriter::add(unsigned int hash, Entry* entry) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
92 |
int index = hash % _num_buckets; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
93 |
entry->set_next(_buckets[index]); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
94 |
_buckets[index] = entry; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
95 |
_bucket_sizes[index] ++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
96 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
97 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
98 |
// Write the compact table's bucket infos |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
99 |
juint* CompactHashtableWriter::dump_table(juint* p, juint** first_bucket, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
100 |
NumberSeq* summary) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
101 |
int index; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
102 |
juint* compact_table = p; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
103 |
// Compute the start of the buckets, include the compact_bucket_infos table |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
104 |
// and the table end offset. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
105 |
juint offset = _num_buckets + 1; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
106 |
*first_bucket = compact_table + offset; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
107 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
108 |
for (index = 0; index < _num_buckets; index++) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
109 |
int bucket_size = _bucket_sizes[index]; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
110 |
if (bucket_size == 1) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
111 |
// bucket with one entry is compacted and only has the symbol offset |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
112 |
compact_table[index] = BUCKET_INFO(offset, COMPACT_BUCKET_TYPE); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
113 |
offset += bucket_size; // each entry contains symbol offset only |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
114 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
115 |
// regular bucket, each entry is a symbol (hash, offset) pair |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
116 |
compact_table[index] = BUCKET_INFO(offset, REGULAR_BUCKET_TYPE); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
117 |
offset += bucket_size * 2; // each hash entry is 2 juints |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
118 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
119 |
if (offset & ~BUCKET_OFFSET_MASK) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
120 |
vm_exit_during_initialization("CompactHashtableWriter::dump_table: Overflow! " |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
121 |
"Too many symbols."); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
122 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
123 |
summary->add(bucket_size); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
124 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
125 |
// Mark the end of the table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
126 |
compact_table[_num_buckets] = BUCKET_INFO(offset, TABLEEND_BUCKET_TYPE); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
127 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
128 |
return compact_table; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
129 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
130 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
131 |
// Write the compact table's entries |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
132 |
juint* CompactHashtableWriter::dump_buckets(juint* compact_table, juint* p, |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
133 |
NumberSeq* summary) { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
134 |
uintx base_address = 0; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
135 |
uintx max_delta = 0; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
136 |
int num_compact_buckets = 0; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
137 |
if (_type == CompactHashtable<Symbol*, char>::_symbol_table) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
138 |
base_address = uintx(MetaspaceShared::shared_rs()->base()); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
139 |
max_delta = uintx(MetaspaceShared::shared_rs()->size()); |
34242
e530decd7c63
8138983: Runtime: implement ranges for Shared*** flags
gziemski
parents:
33589
diff
changeset
|
140 |
assert(max_delta <= MAX_SHARED_DELTA, "range check"); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
141 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
142 |
assert((_type == CompactHashtable<oop, char>::_string_table), "unknown table"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
143 |
assert(UseCompressedOops, "UseCompressedOops is required"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
144 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
145 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
146 |
assert(p != NULL, "sanity"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
147 |
for (int index = 0; index < _num_buckets; index++) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
148 |
juint count = 0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
149 |
int bucket_size = _bucket_sizes[index]; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
150 |
int bucket_type = BUCKET_TYPE(compact_table[index]); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
151 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
152 |
if (bucket_size == 1) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
153 |
assert(bucket_type == COMPACT_BUCKET_TYPE, "Bad bucket type"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
154 |
num_compact_buckets ++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
155 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
156 |
for (Entry* tent = _buckets[index]; tent; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
157 |
tent = tent->next()) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
158 |
if (bucket_type == REGULAR_BUCKET_TYPE) { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
159 |
*p++ = juint(tent->hash()); // write entry hash |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
160 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
161 |
if (_type == CompactHashtable<Symbol*, char>::_symbol_table) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
162 |
uintx deltax = uintx(tent->value()) - base_address; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
163 |
assert(deltax < max_delta, "range check"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
164 |
juint delta = juint(deltax); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
165 |
*p++ = delta; // write entry offset |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
166 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
167 |
*p++ = oopDesc::encode_heap_oop(tent->string()); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
168 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
169 |
count ++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
170 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
171 |
assert(count == _bucket_sizes[index], "sanity"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
172 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
173 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
174 |
// Adjust the hashentry_bytes in CompactHashtableStats. Each compact |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
175 |
// bucket saves 4-byte. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
176 |
_stats->hashentry_bytes -= num_compact_buckets * 4; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
177 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
178 |
return p; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
179 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
180 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
181 |
// Write the compact table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
182 |
void CompactHashtableWriter::dump(char** top, char* end) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
183 |
NumberSeq summary; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
184 |
char* old_top = *top; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
185 |
juint* p = (juint*)(*top); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
186 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
187 |
uintx base_address = uintx(MetaspaceShared::shared_rs()->base()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
188 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
189 |
// Now write the following at the beginning of the table: |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
190 |
// base_address (uintx) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
191 |
// num_entries (juint) |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
192 |
// num_buckets (juint) |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
193 |
*p++ = high(base_address); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
194 |
*p++ = low (base_address); // base address |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
195 |
*p++ = _num_entries; // number of entries in the table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
196 |
*p++ = _num_buckets; // number of buckets in the table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
197 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
198 |
juint* first_bucket = NULL; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
199 |
juint* compact_table = dump_table(p, &first_bucket, &summary); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
200 |
juint* bucket_end = dump_buckets(compact_table, first_bucket, &summary); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
201 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
202 |
assert(bucket_end <= (juint*)end, "cannot write past end"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
203 |
*top = (char*)bucket_end; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
204 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
205 |
if (PrintSharedSpaces) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
206 |
double avg_cost = 0.0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
207 |
if (_num_entries > 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
208 |
avg_cost = double(_required_bytes)/double(_num_entries); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
209 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
210 |
tty->print_cr("Shared %s table stats -------- base: " PTR_FORMAT, |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
211 |
table_name(), (intptr_t)base_address); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
212 |
tty->print_cr("Number of entries : %9d", _num_entries); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
213 |
tty->print_cr("Total bytes used : %9d", (int)((*top) - old_top)); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
214 |
tty->print_cr("Average bytes per entry : %9.3f", avg_cost); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
215 |
tty->print_cr("Average bucket size : %9.3f", summary.avg()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
216 |
tty->print_cr("Variance of bucket size : %9.3f", summary.variance()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
217 |
tty->print_cr("Std. dev. of bucket size: %9.3f", summary.sd()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
218 |
tty->print_cr("Maximum bucket size : %9d", (int)summary.maximum()); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
219 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
220 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
221 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
222 |
const char* CompactHashtableWriter::table_name() { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
223 |
switch (_type) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
224 |
case CompactHashtable<Symbol*, char>::_symbol_table: return "symbol"; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
225 |
case CompactHashtable<oop, char>::_string_table: return "string"; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
226 |
default: |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
227 |
; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
228 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
229 |
return "unknown"; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
230 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
231 |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
232 |
///////////////////////////////////////////////////////////// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
233 |
// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
234 |
// The CompactHashtable implementation |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
235 |
// |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
236 |
template <class T, class N> const char* CompactHashtable<T, N>::init( |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
237 |
CompactHashtableType type, const char* buffer) { |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
238 |
assert(!DumpSharedSpaces, "run-time only"); |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
239 |
_type = type; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
240 |
juint*p = (juint*)buffer; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
241 |
juint upper = *p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
242 |
juint lower = *p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
243 |
_base_address = uintx(jlong_from(upper, lower)); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
244 |
_entry_count = *p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
245 |
_bucket_count = *p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
246 |
_buckets = p; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
247 |
_table_end_offset = BUCKET_OFFSET(p[_bucket_count]); // located at the end of the bucket_info table |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
248 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
249 |
juint *end = _buckets + _table_end_offset; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
250 |
return (const char*)end; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
251 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
252 |
|
28615
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
253 |
template <class T, class N> void CompactHashtable<T, N>::symbols_do(SymbolClosure *cl) { |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
254 |
assert(!DumpSharedSpaces, "run-time only"); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
255 |
for (juint i = 0; i < _bucket_count; i ++) { |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
256 |
juint bucket_info = _buckets[i]; |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
257 |
juint bucket_offset = BUCKET_OFFSET(bucket_info); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
258 |
int bucket_type = BUCKET_TYPE(bucket_info); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
259 |
juint* bucket = _buckets + bucket_offset; |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
260 |
juint* bucket_end = _buckets; |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
261 |
|
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
262 |
Symbol* sym; |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
263 |
if (bucket_type == COMPACT_BUCKET_TYPE) { |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
264 |
sym = (Symbol*)((void*)(_base_address + bucket[0])); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
265 |
cl->do_symbol(&sym); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
266 |
} else { |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
267 |
bucket_end += BUCKET_OFFSET(_buckets[i + 1]); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
268 |
while (bucket < bucket_end) { |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
269 |
sym = (Symbol*)((void*)(_base_address + bucket[1])); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
270 |
cl->do_symbol(&sym); |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
271 |
bucket += 2; |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
272 |
} |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
273 |
} |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
274 |
} |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
275 |
} |
1fb960ea5a7e
8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents:
28363
diff
changeset
|
276 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
277 |
template <class T, class N> void CompactHashtable<T, N>::oops_do(OopClosure* f) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
278 |
assert(!DumpSharedSpaces, "run-time only"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
279 |
assert(_type == _string_table || _bucket_count == 0, "sanity"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
280 |
for (juint i = 0; i < _bucket_count; i ++) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
281 |
juint bucket_info = _buckets[i]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
282 |
juint bucket_offset = BUCKET_OFFSET(bucket_info); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
283 |
int bucket_type = BUCKET_TYPE(bucket_info); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
284 |
juint* bucket = _buckets + bucket_offset; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
285 |
juint* bucket_end = _buckets; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
286 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
287 |
narrowOop o; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
288 |
if (bucket_type == COMPACT_BUCKET_TYPE) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
289 |
o = (narrowOop)bucket[0]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
290 |
f->do_oop(&o); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
291 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
292 |
bucket_end += BUCKET_OFFSET(_buckets[i + 1]); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
293 |
while (bucket < bucket_end) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
294 |
o = (narrowOop)bucket[1]; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
295 |
f->do_oop(&o); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
296 |
bucket += 2; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
297 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
298 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
299 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
300 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
301 |
|
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
302 |
// Explicitly instantiate these types |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
303 |
template class CompactHashtable<Symbol*, char>; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
304 |
template class CompactHashtable<oop, char>; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
305 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
306 |
#ifndef O_BINARY // if defined (Win32) use binary files. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
307 |
#define O_BINARY 0 // otherwise do nothing. |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
308 |
#endif |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
309 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
310 |
//////////////////////////////////////////////////////// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
311 |
// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
312 |
// HashtableTextDump |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
313 |
// |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
314 |
HashtableTextDump::HashtableTextDump(const char* filename) : _fd(-1) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
315 |
struct stat st; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
316 |
if (os::stat(filename, &st) != 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
317 |
quit("Unable to get hashtable dump file size", filename); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
318 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
319 |
_size = st.st_size; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
320 |
_fd = open(filename, O_RDONLY | O_BINARY, 0); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
321 |
if (_fd < 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
322 |
quit("Unable to open hashtable dump file", filename); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
323 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
324 |
_base = os::map_memory(_fd, filename, 0, NULL, _size, true, false); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
325 |
if (_base == NULL) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
326 |
quit("Unable to map hashtable dump file", filename); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
327 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
328 |
_p = _base; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
329 |
_end = _base + st.st_size; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
330 |
_filename = filename; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
331 |
_prefix_type = Unknown; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
332 |
_line_no = 1; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
333 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
334 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
335 |
HashtableTextDump::~HashtableTextDump() { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
336 |
os::unmap_memory((char*)_base, _size); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
337 |
if (_fd >= 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
338 |
close(_fd); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
339 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
340 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
341 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
342 |
void HashtableTextDump::quit(const char* err, const char* msg) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
343 |
vm_exit_during_initialization(err, msg); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
344 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
345 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
346 |
void HashtableTextDump::corrupted(const char *p, const char* msg) { |
31386
e54c60e0359c
8129446: crash when reporting corrupted classfile
kbarrett
parents:
31345
diff
changeset
|
347 |
char info[100]; |
e54c60e0359c
8129446: crash when reporting corrupted classfile
kbarrett
parents:
31345
diff
changeset
|
348 |
jio_snprintf(info, sizeof(info), |
e54c60e0359c
8129446: crash when reporting corrupted classfile
kbarrett
parents:
31345
diff
changeset
|
349 |
"%s. Corrupted at line %d (file pos %d)", |
e54c60e0359c
8129446: crash when reporting corrupted classfile
kbarrett
parents:
31345
diff
changeset
|
350 |
msg, _line_no, (int)(p - _base)); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
351 |
quit(info, _filename); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
352 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
353 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
354 |
bool HashtableTextDump::skip_newline() { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
355 |
if (_p[0] == '\r' && _p[1] == '\n') { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
356 |
_p += 2; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
357 |
} else if (_p[0] == '\n') { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
358 |
_p += 1; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
359 |
} else { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
360 |
corrupted(_p, "Unexpected character"); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
361 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
362 |
_line_no ++; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
363 |
return true; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
364 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
365 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
366 |
int HashtableTextDump::skip(char must_be_char) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
367 |
corrupted_if(remain() < 1); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
368 |
corrupted_if(*_p++ != must_be_char); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
369 |
return 0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
370 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
371 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
372 |
void HashtableTextDump::skip_past(char c) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
373 |
for (;;) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
374 |
corrupted_if(remain() < 1); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
375 |
if (*_p++ == c) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
376 |
return; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
377 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
378 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
379 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
380 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
381 |
void HashtableTextDump::check_version(const char* ver) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
382 |
int len = (int)strlen(ver); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
383 |
corrupted_if(remain() < len); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
384 |
if (strncmp(_p, ver, len) != 0) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
385 |
quit("wrong version of hashtable dump file", _filename); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
386 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
387 |
_p += len; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
388 |
skip_newline(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
389 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
390 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
391 |
void HashtableTextDump::scan_prefix_type() { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
392 |
_p ++; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
393 |
if (strncmp(_p, "SECTION: String", 15) == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
394 |
_p += 15; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
395 |
_prefix_type = StringPrefix; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
396 |
} else if (strncmp(_p, "SECTION: Symbol", 15) == 0) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
397 |
_p += 15; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
398 |
_prefix_type = SymbolPrefix; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
399 |
} else { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
400 |
_prefix_type = Unknown; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
401 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
402 |
skip_newline(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
403 |
} |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
404 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
405 |
int HashtableTextDump::scan_prefix(int* utf8_length) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
406 |
if (*_p == '@') { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
407 |
scan_prefix_type(); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
408 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
409 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
410 |
switch (_prefix_type) { |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
411 |
case SymbolPrefix: |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
412 |
*utf8_length = scan_symbol_prefix(); break; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
413 |
case StringPrefix: |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
414 |
*utf8_length = scan_string_prefix(); break; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
415 |
default: |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
416 |
tty->print_cr("Shared input data type: Unknown."); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
417 |
corrupted(_p, "Unknown data type"); |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
418 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
419 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
420 |
return _prefix_type; |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
421 |
} |
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
422 |
|
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
423 |
int HashtableTextDump::scan_string_prefix() { |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
424 |
// Expect /[0-9]+: / |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31386
diff
changeset
|
425 |
int utf8_length = 0; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
426 |
get_num(':', &utf8_length); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
427 |
if (*_p != ' ') { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
428 |
corrupted(_p, "Wrong prefix format for string"); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
429 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
430 |
_p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
431 |
return utf8_length; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
432 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
433 |
|
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
434 |
int HashtableTextDump::scan_symbol_prefix() { |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
435 |
// Expect /[0-9]+ (-|)[0-9]+: / |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31386
diff
changeset
|
436 |
int utf8_length = 0; |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
437 |
get_num(' ', &utf8_length); |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31386
diff
changeset
|
438 |
if (*_p == '-') { |
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31386
diff
changeset
|
439 |
_p++; |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
440 |
} |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
441 |
int ref_num; |
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
31386
diff
changeset
|
442 |
get_num(':', &ref_num); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
443 |
if (*_p != ' ') { |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
444 |
corrupted(_p, "Wrong prefix format for symbol"); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
445 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
446 |
_p++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
447 |
return utf8_length; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
448 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
449 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
450 |
jchar HashtableTextDump::unescape(const char* from, const char* end, int count) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
451 |
jchar value = 0; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
452 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
453 |
corrupted_if(from + count > end); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
454 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
455 |
for (int i=0; i<count; i++) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
456 |
char c = *from++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
457 |
switch (c) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
458 |
case '0': case '1': case '2': case '3': case '4': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
459 |
case '5': case '6': case '7': case '8': case '9': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
460 |
value = (value << 4) + c - '0'; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
461 |
break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
462 |
case 'a': case 'b': case 'c': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
463 |
case 'd': case 'e': case 'f': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
464 |
value = (value << 4) + 10 + c - 'a'; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
465 |
break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
466 |
case 'A': case 'B': case 'C': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
467 |
case 'D': case 'E': case 'F': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
468 |
value = (value << 4) + 10 + c - 'A'; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
469 |
break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
470 |
default: |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
471 |
ShouldNotReachHere(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
472 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
473 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
474 |
return value; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
475 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
476 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
477 |
void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
478 |
// cache in local vars |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
479 |
const char* from = _p; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
480 |
const char* end = _end; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
481 |
char* to = utf8_buffer; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
482 |
int n = utf8_length; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
483 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
484 |
for (; n > 0 && from < end; n--) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
485 |
if (*from != '\\') { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
486 |
*to++ = *from++; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
487 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
488 |
corrupted_if(from + 2 > end); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
489 |
char c = from[1]; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
490 |
from += 2; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
491 |
switch (c) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
492 |
case 'x': |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
493 |
{ |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
494 |
jchar value = unescape(from, end, 2); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
495 |
from += 2; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
496 |
assert(value <= 0xff, "sanity"); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
497 |
*to++ = (char)(value & 0xff); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
498 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
499 |
break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
500 |
case 't': *to++ = '\t'; break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
501 |
case 'n': *to++ = '\n'; break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
502 |
case 'r': *to++ = '\r'; break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
503 |
case '\\': *to++ = '\\'; break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
504 |
default: |
31345
1bba15125d8d
8015086: add interned strings to the shared archive.
jiangli
parents:
28615
diff
changeset
|
505 |
corrupted(_p, "Unsupported character"); |
28363
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
506 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
507 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
508 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
509 |
corrupted_if(n > 0); // expected more chars but file has ended |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
510 |
_p = from; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
511 |
skip_newline(); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
512 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
513 |
|
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
514 |
// NOTE: the content is NOT the same as |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
515 |
// UTF8::as_quoted_ascii(const char* utf8_str, int utf8_length, char* buf, int buflen). |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
516 |
// We want to escape \r\n\t so that output [1] is more readable; [2] can be more easily |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
517 |
// parsed by scripts; [3] quickly processed by HashtableTextDump::get_utf8() |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
518 |
void HashtableTextDump::put_utf8(outputStream* st, const char* utf8_string, int utf8_length) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
519 |
const char *c = utf8_string; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
520 |
const char *end = c + utf8_length; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
521 |
for (; c < end; c++) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
522 |
switch (*c) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
523 |
case '\t': st->print("\\t"); break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
524 |
case '\r': st->print("\\r"); break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
525 |
case '\n': st->print("\\n"); break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
526 |
case '\\': st->print("\\\\"); break; |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
527 |
default: |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
528 |
if (isprint(*c)) { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
529 |
st->print("%c", *c); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
530 |
} else { |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
531 |
st->print("\\x%02x", ((unsigned int)*c) & 0xff); |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
532 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
533 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
534 |
} |
047115468f16
8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff
changeset
|
535 |
} |