hotspot/src/share/vm/classfile/compactHashtable.hpp
author mchung
Tue, 24 Nov 2015 14:59:17 -0800
changeset 34280 72bfaaffee36
parent 31345 1bba15125d8d
child 34659 3a7071043457
permissions -rw-r--r--
8143911: Reintegrate JEP 259: Stack-Walking API Reviewed-by: coleenp, dfuchs, bchristi, psandoz, sspitsyn Contributed-by: Mandy Chung <mandy.chung@oracle.com>, Brent Christian <brent.christian@oracle.com>, Daniel Fuchs <daniel.fuchs@oracle.com>, Hamlin Li <huaming.li@oracle.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
/*
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
     2
 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     4
 *
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     8
 *
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    13
 * accompanied this code).
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    14
 *
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    18
 *
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    21
 * questions.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    22
 *
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    23
 */
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    24
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    25
#ifndef SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    26
#define SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    27
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    28
#include "classfile/stringTable.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    29
#include "classfile/symbolTable.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    30
#include "memory/allocation.inline.hpp"
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    31
#include "oops/oop.inline.hpp"
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    32
#include "oops/symbol.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    33
#include "services/diagnosticCommand.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    34
#include "utilities/hashtable.hpp"
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    35
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    36
class NumberSeq;
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
// Stats for symbol tables in the CDS archive
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    39
class CompactHashtableStats VALUE_OBJ_CLASS_SPEC {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    40
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    41
  int hashentry_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    42
  int hashentry_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    43
  int bucket_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    44
  int bucket_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    45
};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    46
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    47
/////////////////////////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    48
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    49
// The compact hash table writer. Used at dump time for writing out
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    50
// the compact table to the shared archive.
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
// At dump time, the CompactHashtableWriter obtains all entries from the
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    53
// symbol/string table and adds them to a new temporary hash table. The hash
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    54
// table size (number of buckets) is calculated using
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    55
// '(num_entries + bucket_size - 1) / bucket_size'. The default bucket
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    56
// size is 4 and can be changed by -XX:SharedSymbolTableBucketSize option.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    57
// 4 is chosen because it produces smaller sized bucket on average for
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    58
// faster lookup. It also has relatively small number of empty buckets and
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    59
// good distribution of the entries.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    60
//
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    61
// We use a simple hash function (hash % num_bucket) for the table.
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    62
// The new table is compacted when written out. Please see comments
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    63
// above the CompactHashtable class for the table layout detail. The bucket
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    64
// offsets are written to the archive as part of the compact table. The
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    65
// bucket offset is encoded in the low 30-bit (0-29) and the bucket type
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    66
// (regular or compact) are encoded in bit[31, 30]. For buckets with more
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    67
// than one entry, both hash and entry offset are written to the
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    68
// table. For buckets with only one entry, only the entry offset is written
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    69
// to the table and the buckets are tagged as compact in their type bits.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    70
// Buckets without entry are skipped from the table. Their offsets are
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    71
// still written out for faster lookup.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    72
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    73
class CompactHashtableWriter: public StackObj {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    74
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    75
  class Entry: public CHeapObj<mtSymbol> {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    76
    Entry* _next;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    77
    unsigned int _hash;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    78
    void* _literal;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    79
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    80
  public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    81
    Entry(unsigned int hash, Symbol *symbol) : _next(NULL), _hash(hash), _literal(symbol) {}
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    82
    Entry(unsigned int hash, oop string)     : _next(NULL), _hash(hash), _literal(string) {}
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    83
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    84
    void *value() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    85
      return _literal;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    86
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    87
    Symbol *symbol() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    88
      return (Symbol*)_literal;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    89
    }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    90
    oop string() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    91
      return (oop)_literal;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
    92
    }
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    93
    unsigned int hash() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    94
      return _hash;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    95
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    96
    Entry *next()           {return _next;}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    97
    void set_next(Entry *p) {_next = p;}
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    98
  }; // class CompactHashtableWriter::Entry
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
    99
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   100
private:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   101
  static int number_of_buckets(int num_entries);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   102
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   103
  int _type;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   104
  int _num_entries;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   105
  int _num_buckets;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   106
  juint* _bucket_sizes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   107
  Entry** _buckets;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   108
  int _required_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   109
  CompactHashtableStats* _stats;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   110
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   111
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   112
  // This is called at dump-time only
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   113
  CompactHashtableWriter(int table_type, int num_entries, CompactHashtableStats* stats);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   114
  ~CompactHashtableWriter();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   115
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   116
  int get_required_bytes() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   117
    return _required_bytes;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   118
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   119
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   120
  void add(unsigned int hash, Symbol* symbol) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   121
    add(hash, new Entry(hash, symbol));
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   122
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   123
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   124
  void add(unsigned int hash, oop string) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   125
    add(hash, new Entry(hash, string));
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   126
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   127
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   128
private:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   129
  void add(unsigned int hash, Entry* entry);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   130
  juint* dump_table(juint* p, juint** first_bucket, NumberSeq* summary);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   131
  juint* dump_buckets(juint* table, juint* p, NumberSeq* summary);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   132
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   133
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   134
  void dump(char** top, char* end);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   135
  const char* table_name();
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
#define REGULAR_BUCKET_TYPE       0
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   139
#define COMPACT_BUCKET_TYPE       1
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   140
#define TABLEEND_BUCKET_TYPE      3
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   141
#define BUCKET_OFFSET_MASK        0x3FFFFFFF
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   142
#define BUCKET_OFFSET(info)       ((info) & BUCKET_OFFSET_MASK)
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   143
#define BUCKET_TYPE_SHIFT         30
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   144
#define BUCKET_TYPE(info)         (((info) & ~BUCKET_OFFSET_MASK) >> BUCKET_TYPE_SHIFT)
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   145
#define BUCKET_INFO(offset, type) (((type) << BUCKET_TYPE_SHIFT) | ((offset) & BUCKET_OFFSET_MASK))
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
/////////////////////////////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   148
//
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   149
// CompactHashtable is used to stored the CDS archive's symbol/string table. Used
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   150
// at runtime only to access the compact table from the archive.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   151
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   152
// Because these tables are read-only (no entries can be added/deleted) at run-time
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   153
// and tend to have large number of entries, we try to minimize the footprint
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   154
// cost per entry.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   155
//
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   156
// Layout of compact table in the shared archive:
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   157
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   158
//   uintx base_address;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   159
//   juint num_entries;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   160
//   juint num_buckets;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   161
//   juint bucket_infos[num_buckets+1]; // bit[31,30]: type; bit[29-0]: offset
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   162
//   juint table[]
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   163
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   164
// -----------------------------------
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   165
// | base_address  | num_entries     |
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   166
// |---------------------------------|
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   167
// | num_buckets   | bucket_info0    |
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
// | bucket_info1  | bucket_info2    |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   170
// | bucket_info3    ...             |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   171
// | ....          | table_end_info  |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   172
// |---------------------------------|
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   173
// | entry0                          |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   174
// | entry1                          |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   175
// | entry2                          |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   176
// |                                 |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   177
// | ...                             |
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   178
// -----------------------------------
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   179
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   180
// The size of the bucket_info table is 'num_buckets + 1'. Each entry of the
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   181
// bucket_info table is a 32-bit encoding of the bucket type and bucket offset,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   182
// with the type in the left-most 2-bit and offset in the remaining 30-bit.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   183
// The last entry is a special type. It contains the offset of the last
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   184
// bucket end. We use that information when traversing the compact table.
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
// There are two types of buckets, regular buckets and compact buckets. The
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   187
// compact buckets have '01' in their highest 2-bit, and regular buckets have
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   188
// '00' in their highest 2-bit.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   189
//
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   190
// For normal buckets, each entry is 8 bytes in the table[]:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   191
//   juint hash;    /* symbol/string hash */
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   192
//   union {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   193
//     juint offset;  /* Symbol* sym = (Symbol*)(base_address + offset) */
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   194
//     narrowOop str; /* String narrowOop encoding */
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   195
//   }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
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
// For compact buckets, each entry has only the 4-byte 'offset' in the table[].
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   199
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   200
// See CompactHashtable::lookup() for how the table is searched at runtime.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   201
// See CompactHashtableWriter::dump() for how the table is written at CDS
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   202
// dump time.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   203
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   204
template <class T, class N> class CompactHashtable VALUE_OBJ_CLASS_SPEC {
28822
fa57694ade05 8071962: The SA code needs to be updated to support Symbol lookup from the shared archive.
jiangli
parents: 28615
diff changeset
   205
  friend class VMStructs;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   206
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   207
 public:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   208
  enum CompactHashtableType {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   209
    _symbol_table = 0,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   210
    _string_table = 1
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   211
  };
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   212
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   213
private:
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   214
  CompactHashtableType _type;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   215
  uintx  _base_address;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   216
  juint  _entry_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   217
  juint  _bucket_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   218
  juint  _table_end_offset;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   219
  juint* _buckets;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   220
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   221
  inline Symbol* lookup_entry(CompactHashtable<Symbol*, char>* const t,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   222
                              juint* addr, const char* name, int len) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   223
    Symbol* sym = (Symbol*)((void*)(_base_address + *addr));
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   224
    if (sym->equals(name, len)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   225
      assert(sym->refcount() == -1, "must be shared");
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   226
      return sym;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   227
    }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   228
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   229
    return NULL;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   230
  }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   231
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   232
  inline oop lookup_entry(CompactHashtable<oop, char>* const t,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   233
                        juint* addr, const char* name, int len) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   234
    narrowOop obj = (narrowOop)(*addr);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   235
    oop string = oopDesc::decode_heap_oop(obj);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   236
    if (java_lang_String::equals(string, (jchar*)name, len)) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   237
      return string;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   238
    }
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   239
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   240
    return NULL;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   241
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   242
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   243
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   244
  CompactHashtable() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   245
    _entry_count = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   246
    _bucket_count = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   247
    _table_end_offset = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   248
    _buckets = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   249
  }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   250
  const char* init(CompactHashtableType type, const char *buffer);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   251
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   252
  void reset() {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   253
    _entry_count = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   254
    _bucket_count = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   255
    _table_end_offset = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   256
    _buckets = 0;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   257
  }
28363
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
  // Lookup an entry from the compact table
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   260
  inline T lookup(const N* name, unsigned int hash, int len) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   261
    if (_entry_count > 0) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   262
      assert(!DumpSharedSpaces, "run-time only");
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   263
      int index = hash % _bucket_count;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   264
      juint bucket_info = _buckets[index];
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   265
      juint bucket_offset = BUCKET_OFFSET(bucket_info);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   266
      int   bucket_type = BUCKET_TYPE(bucket_info);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   267
      juint* bucket = _buckets + bucket_offset;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   268
      juint* bucket_end = _buckets;
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
      if (bucket_type == COMPACT_BUCKET_TYPE) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   271
        // the compact bucket has one entry with entry offset only
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   272
        T res = lookup_entry(this, &bucket[0], name, len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   273
        if (res != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   274
          return res;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   275
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   276
      } else {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   277
        // This is a regular bucket, which has more than one
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   278
        // entries. Each entry is a pair of entry (hash, offset).
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   279
        // Seek until the end of the bucket.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   280
        bucket_end += BUCKET_OFFSET(_buckets[index + 1]);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   281
        while (bucket < bucket_end) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   282
          unsigned int h = (unsigned int)(bucket[0]);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   283
          if (h == hash) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   284
            T res = lookup_entry(this, &bucket[1], name, len);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   285
            if (res != NULL) {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   286
              return res;
28363
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
          bucket += 2;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   290
        }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   291
      }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   292
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   293
    return NULL;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   294
  }
28615
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   295
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   296
  // iterate over symbols
1fb960ea5a7e 8067982: Some jcmd /gc/heap_dump tests failed: hprof output contains warning or error.
jiangli
parents: 28363
diff changeset
   297
  void symbols_do(SymbolClosure *cl);
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   298
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   299
  // iterate over strings
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   300
  void oops_do(OopClosure* f);
28363
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
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   305
// Read/Write the contents of a hashtable textual dump (created by
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   306
// SymbolTable::dump and StringTable::dump).
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   307
// Because the dump file may be big (hundred of MB in extreme cases),
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   308
// we use mmap for fast access when reading it.
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   309
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   310
class HashtableTextDump VALUE_OBJ_CLASS_SPEC {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   311
  int _fd;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   312
  const char* _base;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   313
  const char* _p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   314
  const char* _end;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   315
  const char* _filename;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   316
  size_t      _size;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   317
  int         _prefix_type;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   318
  int         _line_no;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   319
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   320
  HashtableTextDump(const char* filename);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   321
  ~HashtableTextDump();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   322
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   323
  enum {
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   324
    SymbolPrefix = 1 << 0,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   325
    StringPrefix = 1 << 1,
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   326
    Unknown = 1 << 2
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   327
  };
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   328
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   329
  void quit(const char* err, const char* msg);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   330
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   331
  inline int remain() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   332
    return (int)(_end - _p);
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
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   335
  void corrupted(const char *p, const char *msg);
28363
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
  inline void corrupted_if(bool cond) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   338
    if (cond) {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   339
      corrupted(_p, NULL);
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   340
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   341
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   342
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   343
  bool skip_newline();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   344
  int skip(char must_be_char);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   345
  void skip_past(char c);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   346
  void check_version(const char* ver);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   347
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   348
  inline bool get_num(char delim, int *utf8_length) {
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   349
    const char* p   = _p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   350
    const char* end = _end;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   351
    int num = 0;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   352
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   353
    while (p < end) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   354
      char c = *p ++;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   355
      if ('0' <= c && c <= '9') {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   356
        num = num * 10 + (c - '0');
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   357
      } else if (c == delim) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   358
        _p = p;
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   359
        *utf8_length = num;
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   360
        return true;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   361
      } else {
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   362
        // Not [0-9], not 'delim'
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   363
        return false;
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   364
      }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   365
    }
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   366
    corrupted(_end, "Incorrect format");
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   367
    ShouldNotReachHere();
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   368
    return false;
28363
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
31345
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   371
  void scan_prefix_type();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   372
  int scan_prefix(int* utf8_length);
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   373
  int scan_string_prefix();
1bba15125d8d 8015086: add interned strings to the shared archive.
jiangli
parents: 28822
diff changeset
   374
  int scan_symbol_prefix();
28363
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   375
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   376
  jchar unescape(const char* from, const char* end, int count);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   377
  void get_utf8(char* utf8_buffer, int utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   378
  static void put_utf8(outputStream* st, const char* utf8_string, int utf8_length);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   379
};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   380
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   381
///////////////////////////////////////////////////////////////////////
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   382
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   383
// jcmd command support for symbol table and string table dumping:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   384
//   VM.symboltable -verbose: for dumping the symbol table
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   385
//   VM.stringtable -verbose: for dumping the string table
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   386
//
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   387
class VM_DumpHashtable : public VM_Operation {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   388
private:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   389
  outputStream* _out;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   390
  int _which;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   391
  bool _verbose;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   392
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   393
  enum {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   394
    DumpSymbols = 1 << 0,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   395
    DumpStrings = 1 << 1,
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   396
    DumpSysDict = 1 << 2  // not implemented yet
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   397
  };
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   398
  VM_DumpHashtable(outputStream* out, int which, bool verbose) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   399
    _out = out;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   400
    _which = which;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   401
    _verbose = verbose;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   402
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   403
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   404
  virtual VMOp_Type type() const { return VMOp_DumpHashtable; }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   405
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   406
  virtual void doit() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   407
    switch (_which) {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   408
    case DumpSymbols:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   409
      SymbolTable::dump(_out, _verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   410
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   411
    case DumpStrings:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   412
      StringTable::dump(_out, _verbose);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   413
      break;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   414
    default:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   415
      ShouldNotReachHere();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   416
    }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   417
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   418
};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   419
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   420
class SymboltableDCmd : public DCmdWithParser {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   421
protected:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   422
  DCmdArgument<bool> _verbose;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   423
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   424
  SymboltableDCmd(outputStream* output, bool heap);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   425
  static const char* name() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   426
    return "VM.symboltable";
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   427
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   428
  static const char* description() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   429
    return "Dump symbol table.";
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
  static const char* impact() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   432
    return "Medium: Depends on Java content.";
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   433
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   434
  static const JavaPermission permission() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   435
    JavaPermission p = {"java.lang.management.ManagementPermission",
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   436
                        "monitor", NULL};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   437
    return p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   438
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   439
  static int num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   440
  virtual void execute(DCmdSource source, TRAPS);
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
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   443
class StringtableDCmd : public DCmdWithParser {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   444
protected:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   445
  DCmdArgument<bool> _verbose;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   446
public:
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   447
  StringtableDCmd(outputStream* output, bool heap);
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   448
  static const char* name() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   449
    return "VM.stringtable";
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
  static const char* description() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   452
    return "Dump string table.";
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   453
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   454
  static const char* impact() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   455
    return "Medium: Depends on Java content.";
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   456
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   457
  static const JavaPermission permission() {
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   458
    JavaPermission p = {"java.lang.management.ManagementPermission",
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   459
                        "monitor", NULL};
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   460
    return p;
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   461
  }
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   462
  static int num_arguments();
047115468f16 8059510: Compact symbol table layout inside shared archive.
jiangli
parents:
diff changeset
   463
  virtual void execute(DCmdSource source, TRAPS);
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
#endif // SHARE_VM_CLASSFILE_COMPACTHASHTABLE_HPP