src/hotspot/share/classfile/compactHashtable.cpp
author phh
Sat, 30 Nov 2019 14:33:05 -0800
changeset 59330 5b96c12f909d
parent 58447 319173c62caa
permissions -rw-r--r--
8234541: C1 emits an empty message when it inlines successfully Summary: Use "inline" as the message when successfull Reviewed-by: thartmann, mdoerr Contributed-by: navy.xliu@gmail.com
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
/*
53911
65f2a401e0eb 8218811: replace open by os::open in hotspot coding
mbaesken
parents: 52514
diff changeset
     2
 * Copyright (c) 1997, 2019, 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"
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51720
diff changeset
    27
#include "classfile/compactHashtable.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"
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    30
#include "memory/dynamicArchive.hpp"
51491
187c84a5efe1 8208658: Make CDS archived heap regions usable even if compressed oop encoding has changed
iklam
parents: 49592
diff changeset
    31
#include "memory/heapShared.inline.hpp"
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    32
#include "memory/metadataFactory.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    33
#include "memory/metaspaceShared.hpp"
46742
24ec8a039c90 8184994: Add Dictionary size logging and jcmd
coleenp
parents: 46522
diff changeset
    34
#include "runtime/vmThread.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    35
#include "utilities/numberSeq.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    36
#include <sys/stat.h>
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    37
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51720
diff changeset
    38
#if INCLUDE_CDS
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    39
/////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    40
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    41
// The compact hash table writer implementations
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    42
//
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    43
CompactHashtableWriter::CompactHashtableWriter(int num_entries,
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    44
                                               CompactHashtableStats* stats) {
58447
319173c62caa 8231606: _method_ordering is not set during CDS dynamic dump time
ccheung
parents: 54927
diff changeset
    45
  Arguments::assert_is_dumping_archive();
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    46
  assert(num_entries >= 0, "sanity");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    47
  _num_buckets = calculate_num_buckets(num_entries);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    48
  assert(_num_buckets > 0, "no buckets");
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    49
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    50
  _num_entries_written = 0;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    51
  _buckets = NEW_C_HEAP_ARRAY(GrowableArray<Entry>*, _num_buckets, mtSymbol);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    52
  for (int i=0; i<_num_buckets; i++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    53
    _buckets[i] = new (ResourceObj::C_HEAP, mtSymbol) GrowableArray<Entry>(0, true, mtSymbol);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    54
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    55
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    56
  _stats = stats;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    57
  _compact_buckets = NULL;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    58
  _compact_entries = NULL;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    59
  _num_empty_buckets = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    60
  _num_value_only_buckets = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    61
  _num_other_buckets = 0;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    62
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    63
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    64
CompactHashtableWriter::~CompactHashtableWriter() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    65
  for (int index = 0; index < _num_buckets; index++) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    66
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    67
    delete bucket;
28363
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
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    70
  FREE_C_HEAP_ARRAY(GrowableArray<Entry>*, _buckets);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    71
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    72
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    73
size_t CompactHashtableWriter::estimate_size(int num_entries) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    74
  int num_buckets = calculate_num_buckets(num_entries);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    75
  size_t bucket_bytes = MetaspaceShared::ro_array_bytesize<u4>(num_buckets + 1);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    76
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    77
  // In worst case, we have no VALUE_ONLY_BUCKET_TYPE, so each entry takes 2 slots
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    78
  int entries_space = 2 * num_entries;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    79
  size_t entry_bytes = MetaspaceShared::ro_array_bytesize<u4>(entries_space);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    80
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    81
  return bucket_bytes
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    82
       + entry_bytes
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    83
       + SimpleCompactHashtable::calculate_header_size();
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    84
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    85
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    86
// Add a symbol entry to the temporary hash table
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    87
void CompactHashtableWriter::add(unsigned int hash, u4 value) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    88
  int index = hash % _num_buckets;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    89
  _buckets[index]->append_if_missing(Entry(hash, value));
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
    90
  _num_entries_written++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    91
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    92
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    93
void CompactHashtableWriter::allocate_table() {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    94
  int entries_space = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    95
  for (int index = 0; index < _num_buckets; index++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    96
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    97
    int bucket_size = bucket->length();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    98
    if (bucket_size == 1) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
    99
      entries_space++;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   100
    } else if (bucket_size > 1) {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   101
      entries_space += 2 * bucket_size;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   102
    }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   103
  }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   104
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   105
  if (entries_space & ~BUCKET_OFFSET_MASK) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   106
    vm_exit_during_initialization("CompactHashtableWriter::allocate_table: Overflow! "
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   107
                                  "Too many entries.");
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   108
  }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   109
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   110
  _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
   111
  _compact_entries = MetaspaceShared::new_ro_array<u4>(entries_space);
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   112
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   113
  _stats->bucket_count    = _num_buckets;
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   114
  _stats->bucket_bytes    = _compact_buckets->size() * BytesPerWord;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   115
  _stats->hashentry_count = _num_entries_written;
46746
ea379ebb9447 8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents: 46742
diff changeset
   116
  _stats->hashentry_bytes = _compact_entries->size() * BytesPerWord;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   117
}
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   118
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   119
// Write the compact table's buckets
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   120
void CompactHashtableWriter::dump_table(NumberSeq* summary) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   121
  u4 offset = 0;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   122
  for (int index = 0; index < _num_buckets; index++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   123
    GrowableArray<Entry>* bucket = _buckets[index];
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   124
    int bucket_size = bucket->length();
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   125
    if (bucket_size == 1) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   126
      // bucket with one entry is compacted and only has the symbol offset
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   127
      _compact_buckets->at_put(index, BUCKET_INFO(offset, VALUE_ONLY_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   128
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   129
      Entry ent = bucket->at(0);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   130
      _compact_entries->at_put(offset++, ent.value());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   131
      _num_value_only_buckets++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   132
    } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   133
      // regular bucket, each entry is a symbol (hash, offset) pair
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   134
      _compact_buckets->at_put(index, BUCKET_INFO(offset, REGULAR_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   135
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   136
      for (int i=0; i<bucket_size; i++) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   137
        Entry ent = bucket->at(i);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   138
        _compact_entries->at_put(offset++, u4(ent.hash())); // write entry hash
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   139
        _compact_entries->at_put(offset++, ent.value());
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   140
      }
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   141
      if (bucket_size == 0) {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   142
        _num_empty_buckets++;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   143
      } else {
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   144
        _num_other_buckets++;
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   145
      }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   146
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   147
    summary->add(bucket_size);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   148
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   149
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   150
  // Mark the end of the buckets
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   151
  _compact_buckets->at_put(_num_buckets, BUCKET_INFO(offset, TABLEEND_BUCKET_TYPE));
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   152
  assert(offset == (u4)_compact_entries->length(), "sanity");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   153
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   154
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
// Write the compact table
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   157
void CompactHashtableWriter::dump(SimpleCompactHashtable *cht, const char* table_name) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   158
  NumberSeq summary;
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   159
  allocate_table();
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   160
  dump_table(&summary);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   161
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   162
  int table_bytes = _stats->bucket_bytes + _stats->hashentry_bytes;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   163
  address base_address = address(SharedBaseAddress);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   164
  cht->init(base_address,  _num_entries_written, _num_buckets,
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   165
            _compact_buckets->data(), _compact_entries->data());
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   166
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   167
  LogMessage(cds, hashtables) msg;
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   168
  if (msg.is_info()) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   169
    double avg_cost = 0.0;
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   170
    if (_num_entries_written > 0) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   171
      avg_cost = double(table_bytes)/double(_num_entries_written);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   172
    }
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   173
    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
   174
                         table_name, (intptr_t)base_address);
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   175
    msg.info("Number of entries       : %9d", _num_entries_written);
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   176
    msg.info("Total bytes used        : %9d", table_bytes);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   177
    msg.info("Average bytes per entry : %9.3f", avg_cost);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   178
    msg.info("Average bucket size     : %9.3f", summary.avg());
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   179
    msg.info("Variance of bucket size : %9.3f", summary.variance());
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   180
    msg.info("Std. dev. of bucket size: %9.3f", summary.sd());
52514
f4e3900c8d08 8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents: 52047
diff changeset
   181
    msg.info("Maximum bucket size     : %9d", (int)summary.maximum());
48962
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   182
    msg.info("Empty buckets           : %9d", _num_empty_buckets);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   183
    msg.info("Value_Only buckets      : %9d", _num_value_only_buckets);
88ad6c676c87 8194994: Remove redundant string streams used for logging
mlarsson
parents: 47765
diff changeset
   184
    msg.info("Other buckets           : %9d", _num_other_buckets);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   185
  }
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
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   188
/////////////////////////////////////////////////////////////
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   189
//
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   190
// The CompactHashtable implementation
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   191
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   192
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   193
void SimpleCompactHashtable::init(address base_address, u4 entry_count, u4 bucket_count, u4* buckets, u4* entries) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   194
  _bucket_count = bucket_count;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   195
  _entry_count = entry_count;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   196
  _base_address = base_address;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   197
  if (DynamicDumpSharedSpaces) {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   198
    _buckets = DynamicArchive::buffer_to_target(buckets);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   199
    _entries = DynamicArchive::buffer_to_target(entries);
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   200
  } else {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   201
    _buckets = buckets;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   202
    _entries = entries;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   203
  }
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   204
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   205
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   206
size_t SimpleCompactHashtable::calculate_header_size() {
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   207
  // We have 5 fields. Each takes up sizeof(intptr_t). See WriteClosure::do_u4
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   208
  size_t bytes = sizeof(intptr_t) * 5;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   209
  return bytes;
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   210
}
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   211
52047
7bc8b456e5ac 8210388: Use hash table to store archived subgraph_info records
iklam
parents: 51823
diff changeset
   212
void SimpleCompactHashtable::serialize_header(SerializeClosure* soc) {
54927
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   213
  // NOTE: if you change this function, you MUST change the number 5 in
1512d88b24c6 8207812: Implement Dynamic CDS Archive
ccheung
parents: 54780
diff changeset
   214
  // calculate_header_size() accordingly.
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   215
  soc->do_ptr((void**)&_base_address);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   216
  soc->do_u4(&_entry_count);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   217
  soc->do_u4(&_bucket_count);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   218
  soc->do_ptr((void**)&_buckets);
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   219
  soc->do_ptr((void**)&_entries);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   220
}
51823
2a51125b2794 8210875: Refactor CompactHashtable
iklam
parents: 51720
diff changeset
   221
#endif // INCLUDE_CDS
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   222
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   223
#ifndef O_BINARY       // if defined (Win32) use binary files.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   224
#define O_BINARY 0     // otherwise do nothing.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   225
#endif
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   226
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   227
////////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   228
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   229
// HashtableTextDump
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   230
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   231
HashtableTextDump::HashtableTextDump(const char* filename) : _fd(-1) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   232
  struct stat st;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   233
  if (os::stat(filename, &st) != 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   234
    quit("Unable to get hashtable dump file size", filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   235
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   236
  _size = st.st_size;
53911
65f2a401e0eb 8218811: replace open by os::open in hotspot coding
mbaesken
parents: 52514
diff changeset
   237
  _fd = os::open(filename, O_RDONLY | O_BINARY, 0);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   238
  if (_fd < 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   239
    quit("Unable to open hashtable dump file", filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   240
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   241
  _base = os::map_memory(_fd, filename, 0, NULL, _size, true, false);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   242
  if (_base == NULL) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   243
    quit("Unable to map hashtable dump file", filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   244
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   245
  _p = _base;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   246
  _end = _base + st.st_size;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   247
  _filename = filename;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   248
  _prefix_type = Unknown;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   249
  _line_no = 1;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   250
}
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
HashtableTextDump::~HashtableTextDump() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   253
  os::unmap_memory((char*)_base, _size);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   254
  if (_fd >= 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   255
    close(_fd);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   256
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   257
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   258
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   259
void HashtableTextDump::quit(const char* err, const char* msg) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   260
  vm_exit_during_initialization(err, msg);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   261
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   262
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   263
void HashtableTextDump::corrupted(const char *p, const char* msg) {
31386
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   264
  char info[100];
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   265
  jio_snprintf(info, sizeof(info),
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   266
               "%s. Corrupted at line %d (file pos %d)",
e54c60e0359c 8129446: crash when reporting corrupted classfile
kbarrett
parents: 31345
diff changeset
   267
               msg, _line_no, (int)(p - _base));
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   268
  quit(info, _filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   269
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   270
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   271
bool HashtableTextDump::skip_newline() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   272
  if (_p[0] == '\r' && _p[1] == '\n') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   273
    _p += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   274
  } else if (_p[0] == '\n') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   275
    _p += 1;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   276
  } else {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   277
    corrupted(_p, "Unexpected character");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   278
  }
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   279
  _line_no++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   280
  return true;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   281
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   282
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   283
int HashtableTextDump::skip(char must_be_char) {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   284
  corrupted_if(remain() < 1, "Truncated");
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   285
  corrupted_if(*_p++ != must_be_char, "Unexpected character");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   286
  return 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   287
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   288
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   289
void HashtableTextDump::skip_past(char c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   290
  for (;;) {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   291
    corrupted_if(remain() < 1, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   292
    if (*_p++ == c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   293
      return;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   294
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   295
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   296
}
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
void HashtableTextDump::check_version(const char* ver) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   299
  int len = (int)strlen(ver);
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   300
  corrupted_if(remain() < len, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   301
  if (strncmp(_p, ver, len) != 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   302
    quit("wrong version of hashtable dump file", _filename);
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
  _p += len;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   305
  skip_newline();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   306
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   307
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   308
void HashtableTextDump::scan_prefix_type() {
37995
92aec042a43b 8150607: Clean up CompactHashtable
iklam
parents: 35868
diff changeset
   309
  _p++;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   310
  if (strncmp(_p, "SECTION: String", 15) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   311
    _p += 15;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   312
    _prefix_type = StringPrefix;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   313
  } else if (strncmp(_p, "SECTION: Symbol", 15) == 0) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   314
    _p += 15;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   315
    _prefix_type = SymbolPrefix;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   316
  } else {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   317
    _prefix_type = Unknown;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   318
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   319
  skip_newline();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   320
}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   321
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   322
int HashtableTextDump::scan_prefix(int* utf8_length) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   323
  if (*_p == '@') {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   324
    scan_prefix_type();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   325
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   326
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   327
  switch (_prefix_type) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   328
  case SymbolPrefix:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   329
    *utf8_length = scan_symbol_prefix(); break;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   330
  case StringPrefix:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   331
    *utf8_length = scan_string_prefix(); break;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   332
  default:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   333
    tty->print_cr("Shared input data type: Unknown.");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   334
    corrupted(_p, "Unknown data type");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   335
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   336
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   337
  return _prefix_type;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   338
}
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   339
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   340
int HashtableTextDump::scan_string_prefix() {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   341
  // Expect /[0-9]+: /
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   342
  int utf8_length = 0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   343
  get_num(':', &utf8_length);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   344
  if (*_p != ' ') {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   345
    corrupted(_p, "Wrong prefix format for string");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   346
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   347
  _p++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   348
  return utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   349
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   350
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   351
int HashtableTextDump::scan_symbol_prefix() {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   352
  // Expect /[0-9]+ (-|)[0-9]+: /
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   353
  int utf8_length = 0;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   354
  get_num(' ', &utf8_length);
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   355
  if (*_p == '-') {
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   356
    _p++;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   357
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   358
  int ref_num;
33589
7cbd1b2c139b 8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents: 31386
diff changeset
   359
  get_num(':', &ref_num);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   360
  if (*_p != ' ') {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   361
    corrupted(_p, "Wrong prefix format for symbol");
28363
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
  _p++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   364
  return utf8_length;
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   367
jchar HashtableTextDump::unescape(const char* from, const char* end, int count) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   368
  jchar value = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   369
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   370
  corrupted_if(from + count > end, "Truncated");
28363
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
  for (int i=0; i<count; i++) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   373
    char c = *from++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   374
    switch (c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   375
    case '0': case '1': case '2': case '3': case '4':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   376
    case '5': case '6': case '7': case '8': case '9':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   377
      value = (value << 4) + c - '0';
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   378
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   379
    case 'a': case 'b': case 'c':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   380
    case 'd': case 'e': case 'f':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   381
      value = (value << 4) + 10 + c - 'a';
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   382
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   383
    case 'A': case 'B': case 'C':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   384
    case 'D': case 'E': case 'F':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   385
      value = (value << 4) + 10 + c - 'A';
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   386
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   387
    default:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   388
      ShouldNotReachHere();
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
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   391
  return value;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   392
}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   393
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   394
void HashtableTextDump::get_utf8(char* utf8_buffer, int utf8_length) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   395
  // cache in local vars
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   396
  const char* from = _p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   397
  const char* end = _end;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   398
  char* to = utf8_buffer;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   399
  int n = utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   400
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   401
  for (; n > 0 && from < end; n--) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   402
    if (*from != '\\') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   403
      *to++ = *from++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   404
    } else {
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   405
      corrupted_if(from + 2 > end, "Truncated");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   406
      char c = from[1];
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   407
      from += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   408
      switch (c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   409
      case 'x':
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   410
        {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   411
          jchar value = unescape(from, end, 2);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   412
          from += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   413
          assert(value <= 0xff, "sanity");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   414
          *to++ = (char)(value & 0xff);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   415
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   416
        break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   417
      case 't':  *to++ = '\t'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   418
      case 'n':  *to++ = '\n'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   419
      case 'r':  *to++ = '\r'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   420
      case '\\': *to++ = '\\'; break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   421
      default:
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28615
diff changeset
   422
        corrupted(_p, "Unsupported character");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   423
      }
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
  }
35868
bf29f15cdf30 8147500: The HashtableTextDump::get_num() should check for integer overflow
jiangli
parents: 34659
diff changeset
   426
  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
   427
  _p = from;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   428
  skip_newline();
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   431
// NOTE: the content is NOT the same as
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   432
// 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
   433
// 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
   434
// parsed by scripts; [3] quickly processed by HashtableTextDump::get_utf8()
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   435
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
   436
  const char *c = utf8_string;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   437
  const char *end = c + utf8_length;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   438
  for (; c < end; c++) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   439
    switch (*c) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   440
    case '\t': st->print("\\t"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   441
    case '\r': st->print("\\r"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   442
    case '\n': st->print("\\n"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   443
    case '\\': st->print("\\\\"); break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   444
    default:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   445
      if (isprint(*c)) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   446
        st->print("%c", *c);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   447
      } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   448
        st->print("\\x%02x", ((unsigned int)*c) & 0xff);
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
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   451
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   452
}