src/hotspot/share/classfile/compactHashtable.cpp
author stefank
Thu, 15 Mar 2018 21:24:10 +0100
changeset 49592 77fb0be7d19f
parent 48962 88ad6c676c87
child 51491 187c84a5efe1
permissions -rw-r--r--
8199946: Move load/store and encode/decode out of oopDesc Reviewed-by: eosterlund, coleenp, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     1
/*
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
     2
 * Copyright (c) 1997, 2018, 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"
47765
b7c7428eaab9 8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents: 47216
diff changeset
    26
#include "jvm.h"
34659
3a7071043457 8143615: compactHashtable.hpp includes .inline.hpp file
iklam
parents: 34242
diff changeset
    27
#include "classfile/compactHashtable.inline.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    28
#include "classfile/javaClasses.hpp"
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42565
diff changeset
    29
#include "logging/logMessage.hpp"
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    30
#include "memory/metadataFactory.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    31
#include "memory/metaspaceShared.hpp"
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 48962
diff changeset
    32
#include "oops/compressedOops.inline.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46522
diff changeset
    33
#include "runtime/vmThread.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    34
#include "utilities/numberSeq.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    35
#include <sys/stat.h>
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    36
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    37
/////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    38
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    39
// The compact hash table writer implementations
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    40
//
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    41
CompactHashtableWriter::CompactHashtableWriter(int num_buckets,
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    42
                                               CompactHashtableStats* stats) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    43
  assert(DumpSharedSpaces, "dump-time only");
38647
e17e25c51396 8157097: OptionsValidation/TestOptionsWithRanges.java crashes at CompactHashtableWriter::add during StringTable::copy_shared_string
rehn
parents: 37995
diff changeset
    44
  assert(num_buckets > 0, "no buckets");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    45
  _num_buckets = num_buckets;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    46
  _num_entries = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    47
  _buckets = NEW_C_HEAP_ARRAY(GrowableArray<Entry>*, _num_buckets, mtSymbol);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    48
  for (int i=0; i<_num_buckets; i++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    49
    _buckets[i] = new (ResourceObj::C_HEAP, mtSymbol) GrowableArray<Entry>(0, true, mtSymbol);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    50
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    51
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    52
  _stats = stats;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    53
  _compact_buckets = NULL;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    54
  _compact_entries = NULL;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    55
  _num_empty_buckets = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    56
  _num_value_only_buckets = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    57
  _num_other_buckets = 0;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    58
}
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
CompactHashtableWriter::~CompactHashtableWriter() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    61
  for (int index = 0; index < _num_buckets; index++) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    62
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    63
    delete bucket;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    64
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    65
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    66
  FREE_C_HEAP_ARRAY(GrowableArray<Entry>*, _buckets);
28363
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    69
// Add a symbol entry to the temporary hash table
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    70
void CompactHashtableWriter::add(unsigned int hash, u4 value) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    71
  int index = hash % _num_buckets;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    72
  _buckets[index]->append_if_missing(Entry(hash, value));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    73
  _num_entries++;
28363
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
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    76
void CompactHashtableWriter::allocate_table() {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    77
  int entries_space = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    78
  for (int index = 0; index < _num_buckets; index++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    79
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    80
    int bucket_size = bucket->length();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    81
    if (bucket_size == 1) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    82
      entries_space++;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    83
    } else {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    84
      entries_space += 2 * bucket_size;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    85
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    86
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    87
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    88
  if (entries_space & ~BUCKET_OFFSET_MASK) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    89
    vm_exit_during_initialization("CompactHashtableWriter::allocate_table: Overflow! "
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    90
                                  "Too many entries.");
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    91
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    92
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    93
  _compact_buckets = MetaspaceShared::new_ro_array<u4>(_num_buckets + 1);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    94
  _compact_entries = MetaspaceShared::new_ro_array<u4>(entries_space);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    95
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    96
  _stats->bucket_count    = _num_buckets;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    97
  _stats->bucket_bytes    = _compact_buckets->size() * BytesPerWord;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    98
  _stats->hashentry_count = _num_entries;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
    99
  _stats->hashentry_bytes = _compact_entries->size() * BytesPerWord;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   100
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   101
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   102
// Write the compact table's buckets
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   103
void CompactHashtableWriter::dump_table(NumberSeq* summary) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   104
  u4 offset = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   105
  for (int index = 0; index < _num_buckets; index++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   106
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   107
    int bucket_size = bucket->length();
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   108
    if (bucket_size == 1) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   109
      // bucket with one entry is compacted and only has the symbol offset
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   110
      _compact_buckets->at_put(index, BUCKET_INFO(offset, VALUE_ONLY_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   111
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   112
      Entry ent = bucket->at(0);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   113
      _compact_entries->at_put(offset++, ent.value());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   114
      _num_value_only_buckets++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   115
    } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   116
      // regular bucket, each entry is a symbol (hash, offset) pair
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   117
      _compact_buckets->at_put(index, BUCKET_INFO(offset, REGULAR_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   118
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   119
      for (int i=0; i<bucket_size; i++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   120
        Entry ent = bucket->at(i);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   121
        _compact_entries->at_put(offset++, u4(ent.hash())); // write entry hash
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   122
        _compact_entries->at_put(offset++, ent.value());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   123
      }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   124
      if (bucket_size == 0) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   125
        _num_empty_buckets++;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   126
      } else {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   127
        _num_other_buckets++;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   128
      }
28363
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
    summary->add(bucket_size);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   131
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   132
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   133
  // Mark the end of the buckets
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   134
  _compact_buckets->at_put(_num_buckets, BUCKET_INFO(offset, TABLEEND_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   135
  assert(offset == (u4)_compact_entries->length(), "sanity");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   136
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   137
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   138
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   139
// Write the compact table
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   140
void CompactHashtableWriter::dump(SimpleCompactHashtable *cht, const char* table_name) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   141
  NumberSeq summary;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   142
  allocate_table();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   143
  dump_table(&summary);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   144
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   145
  int table_bytes = _stats->bucket_bytes + _stats->hashentry_bytes;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   146
  address base_address = address(MetaspaceShared::shared_rs()->base());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   147
  cht->init(base_address,  _num_entries, _num_buckets,
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   148
            _compact_buckets->data(), _compact_entries->data());
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   149
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   150
  LogMessage(cds, hashtables) msg;
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   151
  if (msg.is_info()) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   152
    double avg_cost = 0.0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   153
    if (_num_entries > 0) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   154
      avg_cost = double(table_bytes)/double(_num_entries);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   155
    }
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   156
    msg.info("Shared %s table stats -------- base: " PTR_FORMAT,
46522
86b13b03a053 8176132: -XX:+PrintSharedSpaces should be converted to use Unified Logging.
rprotacio
parents: 42565
diff changeset
   157
                         table_name, (intptr_t)base_address);
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   158
    msg.info("Number of entries       : %9d", _num_entries);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   159
    msg.info("Total bytes used        : %9d", table_bytes);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   160
    msg.info("Average bytes per entry : %9.3f", avg_cost);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   161
    msg.info("Average bucket size     : %9.3f", summary.avg());
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   162
    msg.info("Variance of bucket size : %9.3f", summary.variance());
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   163
    msg.info("Std. dev. of bucket size: %9.3f", summary.sd());
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   164
    msg.info("Empty buckets           : %9d", _num_empty_buckets);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   165
    msg.info("Value_Only buckets      : %9d", _num_value_only_buckets);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   166
    msg.info("Other buckets           : %9d", _num_other_buckets);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   167
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   168
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   169
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   170
/////////////////////////////////////////////////////////////
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   171
//
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   172
// Customization for dumping Symbol and String tables
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   173
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   174
void CompactSymbolTableWriter::add(unsigned int hash, Symbol *symbol) {
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   175
  uintx deltax = MetaspaceShared::object_delta(symbol);
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   176
  // When the symbols are stored into the archive, we already check that
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   177
  // they won't be more than MAX_SHARED_DELTA from the base address, or
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   178
  // else the dumping would have been aborted.
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   179
  assert(deltax <= MAX_SHARED_DELTA, "must not be");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   180
  u4 delta = u4(deltax);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   181
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   182
  CompactHashtableWriter::add(hash, delta);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   183
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   184
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   185
void CompactStringTableWriter::add(unsigned int hash, oop string) {
49592
77fb0be7d19f 8199946: Move load/store and encode/decode out of oopDesc
stefank
parents: 48962
diff changeset
   186
  CompactHashtableWriter::add(hash, CompressedOops::encode(string));
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   187
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   188
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   189
void CompactSymbolTableWriter::dump(CompactHashtable<Symbol*, char> *cht) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   190
  CompactHashtableWriter::dump(cht, "symbol");
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   191
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   192
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   193
void CompactStringTableWriter::dump(CompactHashtable<oop, char> *cht) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   194
  CompactHashtableWriter::dump(cht, "string");
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   195
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   196
28363
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
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   199
// The CompactHashtable implementation
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   200
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   201
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   202
void SimpleCompactHashtable::serialize(SerializeClosure* soc) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   203
  soc->do_ptr((void**)&_base_address);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   204
  soc->do_u4(&_entry_count);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   205
  soc->do_u4(&_bucket_count);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   206
  soc->do_ptr((void**)&_buckets);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   207
  soc->do_ptr((void**)&_entries);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   208
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   209
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   210
bool SimpleCompactHashtable::exists(u4 value) {
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   211
  assert(!DumpSharedSpaces, "run-time only");
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   212
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   213
  if (_entry_count == 0) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   214
    return false;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   215
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   216
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   217
  unsigned int hash = (unsigned int)value;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   218
  int index = hash % _bucket_count;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   219
  u4 bucket_info = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   220
  u4 bucket_offset = BUCKET_OFFSET(bucket_info);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   221
  int bucket_type = BUCKET_TYPE(bucket_info);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   222
  u4* entry = _entries + bucket_offset;
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   223
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   224
  if (bucket_type == VALUE_ONLY_BUCKET_TYPE) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   225
    return (entry[0] == value);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   226
  } else {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   227
    u4*entry_max = _entries + BUCKET_OFFSET(_buckets[index + 1]);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   228
    while (entry <entry_max) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   229
      if (entry[1] == value) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   230
        return true;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   231
      }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   232
      entry += 2;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   233
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   234
    return false;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   235
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   236
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   237
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   238
template <class I>
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   239
inline void SimpleCompactHashtable::iterate(const I& iterator) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   240
  for (u4 i = 0; i < _bucket_count; i++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   241
    u4 bucket_info = _buckets[i];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   242
    u4 bucket_offset = BUCKET_OFFSET(bucket_info);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   243
    int bucket_type = BUCKET_TYPE(bucket_info);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   244
    u4* entry = _entries + bucket_offset;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   245
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   246
    if (bucket_type == VALUE_ONLY_BUCKET_TYPE) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   247
      iterator.do_value(_base_address, entry[0]);
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   248
    } else {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   249
      u4*entry_max = _entries + BUCKET_OFFSET(_buckets[i + 1]);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   250
      while (entry < entry_max) {
39615
9ab0913a0e65 8159890: SIGSEGV with UseStringDeduplication and UseSharedSpaces/RequireSharedSpaces
pliden
parents: 38647
diff changeset
   251
        iterator.do_value(_base_address, entry[1]);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   252
        entry += 2;
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   253
      }
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   254
    }
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   255
  }
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   256
}
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   257
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   258
template <class T, class N> void CompactHashtable<T, N>::serialize(SerializeClosure* soc) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   259
  SimpleCompactHashtable::serialize(soc);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   260
  soc->do_u4(&_type);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   261
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   262
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   263
class CompactHashtable_SymbolIterator {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   264
  SymbolClosure* const _closure;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   265
public:
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   266
  CompactHashtable_SymbolIterator(SymbolClosure *cl) : _closure(cl) {}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   267
  inline void do_value(address base_address, u4 offset) const {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   268
    Symbol* sym = (Symbol*)((void*)(base_address + offset));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   269
    _closure->do_symbol(&sym);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   270
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   271
};
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   272
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   273
template <class T, class N> void CompactHashtable<T, N>::symbols_do(SymbolClosure *cl) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   274
  CompactHashtable_SymbolIterator iterator(cl);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   275
  iterate(iterator);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   276
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   277
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   278
class CompactHashtable_OopIterator {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   279
  OopClosure* const _closure;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   280
public:
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   281
  CompactHashtable_OopIterator(OopClosure *cl) : _closure(cl) {}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   282
  inline void do_value(address base_address, u4 offset) const {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   283
    narrowOop o = (narrowOop)offset;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   284
    _closure->do_oop(&o);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   285
  }
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   286
};
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   287
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   288
template <class T, class N> void CompactHashtable<T, N>::oops_do(OopClosure* cl) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   289
  assert(_type == _string_table || _bucket_count == 0, "sanity");
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   290
  CompactHashtable_OopIterator iterator(cl);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   291
  iterate(iterator);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   292
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   293
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   294
// Explicitly instantiate these types
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   295
template class CompactHashtable<Symbol*, char>;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   296
template class CompactHashtable<oop, char>;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   297
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   298
#ifndef O_BINARY       // if defined (Win32) use binary files.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   299
#define O_BINARY 0     // otherwise do nothing.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   300
#endif
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   301
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   302
////////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   303
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   304
// HashtableTextDump
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
HashtableTextDump::HashtableTextDump(const char* filename) : _fd(-1) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   307
  struct stat st;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   308
  if (os::stat(filename, &st) != 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   309
    quit("Unable to get hashtable dump file size", filename);
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
  _size = st.st_size;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   312
  _fd = open(filename, O_RDONLY | O_BINARY, 0);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   313
  if (_fd < 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   314
    quit("Unable to open hashtable dump file", filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   315
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   316
  _base = os::map_memory(_fd, filename, 0, NULL, _size, true, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   317
  if (_base == NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   318
    quit("Unable to map hashtable dump file", filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   319
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   320
  _p = _base;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   321
  _end = _base + st.st_size;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   322
  _filename = filename;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   323
  _prefix_type = Unknown;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   324
  _line_no = 1;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   325
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   326
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   327
HashtableTextDump::~HashtableTextDump() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   328
  os::unmap_memory((char*)_base, _size);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   329
  if (_fd >= 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   330
    close(_fd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   331
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   332
}
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
void HashtableTextDump::quit(const char* err, const char* msg) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   335
  vm_exit_during_initialization(err, msg);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   336
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   337
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   338
void HashtableTextDump::corrupted(const char *p, const char* msg) {
31386
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   339
  char info[100];
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   340
  jio_snprintf(info, sizeof(info),
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   341
               "%s. Corrupted at line %d (file pos %d)",
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   342
               msg, _line_no, (int)(p - _base));
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   343
  quit(info, _filename);
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   346
bool HashtableTextDump::skip_newline() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   347
  if (_p[0] == '\r' && _p[1] == '\n') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   348
    _p += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   349
  } else if (_p[0] == '\n') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   350
    _p += 1;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   351
  } else {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   352
    corrupted(_p, "Unexpected character");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   353
  }
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   354
  _line_no++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   355
  return true;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   356
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   357
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   358
int HashtableTextDump::skip(char must_be_char) {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   359
  corrupted_if(remain() < 1, "Truncated");
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   360
  corrupted_if(*_p++ != must_be_char, "Unexpected character");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   361
  return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   362
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   364
void HashtableTextDump::skip_past(char c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   365
  for (;;) {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   366
    corrupted_if(remain() < 1, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   367
    if (*_p++ == c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   368
      return;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   369
    }
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   373
void HashtableTextDump::check_version(const char* ver) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   374
  int len = (int)strlen(ver);
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   375
  corrupted_if(remain() < len, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   376
  if (strncmp(_p, ver, len) != 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   377
    quit("wrong version of hashtable dump file", _filename);
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
  _p += len;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   380
  skip_newline();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   381
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   382
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   383
void HashtableTextDump::scan_prefix_type() {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   384
  _p++;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   385
  if (strncmp(_p, "SECTION: String", 15) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   386
    _p += 15;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   387
    _prefix_type = StringPrefix;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   388
  } else if (strncmp(_p, "SECTION: Symbol", 15) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   389
    _p += 15;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   390
    _prefix_type = SymbolPrefix;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   391
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   392
    _prefix_type = Unknown;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   393
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   394
  skip_newline();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   395
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   396
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   397
int HashtableTextDump::scan_prefix(int* utf8_length) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   398
  if (*_p == '@') {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   399
    scan_prefix_type();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   400
  }
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
  switch (_prefix_type) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   403
  case SymbolPrefix:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   404
    *utf8_length = scan_symbol_prefix(); break;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   405
  case StringPrefix:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   406
    *utf8_length = scan_string_prefix(); break;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   407
  default:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   408
    tty->print_cr("Shared input data type: Unknown.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   409
    corrupted(_p, "Unknown data type");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   410
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   411
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   412
  return _prefix_type;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   413
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   414
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   415
int HashtableTextDump::scan_string_prefix() {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   416
  // Expect /[0-9]+: /
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   417
  int utf8_length = 0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   418
  get_num(':', &utf8_length);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   419
  if (*_p != ' ') {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   420
    corrupted(_p, "Wrong prefix format for string");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   421
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   422
  _p++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   423
  return utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   424
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   425
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   426
int HashtableTextDump::scan_symbol_prefix() {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   427
  // Expect /[0-9]+ (-|)[0-9]+: /
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   428
  int utf8_length = 0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   429
  get_num(' ', &utf8_length);
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   430
  if (*_p == '-') {
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   431
    _p++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   432
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   433
  int ref_num;
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   434
  get_num(':', &ref_num);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   435
  if (*_p != ' ') {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   436
    corrupted(_p, "Wrong prefix format for symbol");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   437
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   438
  _p++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   439
  return utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   440
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   441
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   442
jchar HashtableTextDump::unescape(const char* from, const char* end, int count) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   443
  jchar value = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   444
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   445
  corrupted_if(from + count > end, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   446
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   447
  for (int i=0; i<count; i++) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   448
    char c = *from++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   449
    switch (c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   450
    case '0': case '1': case '2': case '3': case '4':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   451
    case '5': case '6': case '7': case '8': case '9':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   452
      value = (value << 4) + c - '0';
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   453
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   454
    case 'a': case 'b': case 'c':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   455
    case 'd': case 'e': case 'f':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   456
      value = (value << 4) + 10 + c - 'a';
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   457
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   458
    case 'A': case 'B': case 'C':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   459
    case 'D': case 'E': case 'F':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   460
      value = (value << 4) + 10 + c - 'A';
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
    default:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   463
      ShouldNotReachHere();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   464
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   465
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   466
  return value;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   467
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   468
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   469
void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   470
  // cache in local vars
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   471
  const char* from = _p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   472
  const char* end = _end;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   473
  char* to = utf8_buffer;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   474
  int n = utf8_length;
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
  for (; n > 0 && from < end; n--) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   477
    if (*from != '\\') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   478
      *to++ = *from++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   479
    } else {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   480
      corrupted_if(from + 2 > end, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   481
      char c = from[1];
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   482
      from += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   483
      switch (c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   484
      case 'x':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   485
        {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   486
          jchar value = unescape(from, end, 2);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   487
          from += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   488
          assert(value <= 0xff, "sanity");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   489
          *to++ = (char)(value & 0xff);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   490
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   491
        break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   492
      case 't':  *to++ = '\t'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   493
      case 'n':  *to++ = '\n'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   494
      case 'r':  *to++ = '\r'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   495
      case '\\': *to++ = '\\'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   496
      default:
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   497
        corrupted(_p, "Unsupported character");
28363
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
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   500
  }
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   501
  corrupted_if(n > 0, "Truncated"); // expected more chars but file has ended
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   502
  _p = from;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   503
  skip_newline();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   504
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   505
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   506
// NOTE: the content is NOT the same as
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   507
// 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
   508
// 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
   509
// parsed by scripts; [3] quickly processed by HashtableTextDump::get_utf8()
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   510
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
   511
  const char *c = utf8_string;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   512
  const char *end = c + utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   513
  for (; c < end; c++) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   514
    switch (*c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   515
    case '\t': st->print("\\t"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   516
    case '\r': st->print("\\r"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   517
    case '\n': st->print("\\n"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   518
    case '\\': st->print("\\\\"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   519
    default:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   520
      if (isprint(*c)) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   521
        st->print("%c", *c);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   522
      } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   523
        st->print("\\x%02x", ((unsigned int)*c) & 0xff);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   524
      }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   525
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   526
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   527
}