src/hotspot/share/classfile/classListParser.hpp
author lfoltan
Mon, 21 Oct 2019 13:13:16 -0400
changeset 58722 cba8afa5cfed
parent 53244 9807daeb47c4
permissions -rw-r--r--
8231844: Enhance type signature characters in classfile_constants.h and improve the JVM to use type signature characters more consistently Summary: Increase the use of type signature constants instead of hard coded characters within the JVM. Reviewed-by: coleenp, dholmes, fparain Contributed-by: lois.foltan@oracle.com, john.r.rose@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
     2
 * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     4
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     8
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    13
 * accompanied this code).
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    14
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    18
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    21
 * questions.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    22
 *
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    23
 */
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
    25
#ifndef SHARE_CLASSFILE_CLASSLISTPARSER_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
    26
#define SHARE_CLASSFILE_CLASSLISTPARSER_HPP
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    27
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    28
#include "utilities/exceptions.hpp"
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    29
#include "utilities/globalDefinitions.hpp"
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 48383
diff changeset
    30
#include "utilities/growableArray.hpp"
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 48383
diff changeset
    31
#include "utilities/hashtable.inline.hpp"
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    32
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 48383
diff changeset
    33
class ID2KlassTable : public KVHashtable<int, InstanceKlass*, mtInternal> {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    34
public:
52631
3009ca99de32 8213587: Speed up CDS dump time by using resizable hashtables
iklam
parents: 48383
diff changeset
    35
  ID2KlassTable() : KVHashtable<int, InstanceKlass*, mtInternal>(1987) {}
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    36
};
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    37
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    38
class ClassListParser : public StackObj {
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    39
  enum {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    40
    _unspecified      = -999,
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    41
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    42
    // Max number of bytes allowed per line in the classlist.
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    43
    // Theoretically Java class names could be 65535 bytes in length. Also, an input line
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    44
    // could have a very long path name up to JVM_MAXPATHLEN bytes in length. In reality,
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    45
    // 4K bytes is more than enough.
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    46
    _max_allowed_line_len = 4096,
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    47
    _line_buf_extra       = 10, // for detecting input too long
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    48
    _line_buf_size        = _max_allowed_line_len + _line_buf_extra
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    49
  };
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    50
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    51
  static ClassListParser* _instance; // the singleton.
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    52
  const char* _classlist_file;
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    53
  FILE* _file;
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    54
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    55
  ID2KlassTable _id2klass_table;
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    56
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    57
  // The following field contains information from the *current* line being
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    58
  // parsed.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    59
  char                _line[_line_buf_size];  // The buffer that holds the current line. Some characters in
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    60
                                              // the buffer may be overwritten by '\0' during parsing.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    61
  int                 _line_len;              // Original length of the input line.
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    62
  int                 _line_no;               // Line number for current line being parsed
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    63
  const char*         _class_name;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    64
  int                 _id;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    65
  int                 _super;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    66
  GrowableArray<int>* _interfaces;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    67
  bool                _interfaces_specified;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    68
  const char*         _source;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    69
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    70
  bool parse_int_option(const char* option_name, int* value);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    71
  InstanceKlass* load_class_from_source(Symbol* class_name, TRAPS);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    72
  ID2KlassTable *table() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    73
    return &_id2klass_table;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    74
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    75
  InstanceKlass* lookup_class_by_id(int id);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    76
  void print_specified_interfaces();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    77
  void print_actual_interfaces(InstanceKlass *ik);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    78
public:
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    79
  ClassListParser(const char* file);
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    80
  ~ClassListParser();
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    81
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    82
  static ClassListParser* instance() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    83
    return _instance;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    84
  }
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
    85
  bool parse_one_line();
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    86
  char* _token;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    87
  void error(const char* msg, ...);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    88
  void parse_int(int* value);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    89
  bool try_parse_int(int* value);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    90
  bool skip_token(const char* option_name);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    91
  void skip_whitespaces();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    92
  void skip_non_whitespaces();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    93
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    94
  bool is_id_specified() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    95
    return _id != _unspecified;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    96
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    97
  bool is_super_specified() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    98
    return _super != _unspecified;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
    99
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   100
  bool are_interfaces_specified() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   101
    return _interfaces->length() > 0;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   102
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   103
  int id() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   104
    assert(is_id_specified(), "do not query unspecified id");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   105
    return _id;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   106
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   107
  int super() {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   108
    assert(is_super_specified(), "do not query unspecified super");
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   109
    return _super;
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   110
  }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   111
  void check_already_loaded(const char* which, int id) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   112
    if (_id2klass_table.lookup(id) == NULL) {
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   113
      error("%s id %d is not yet loaded", which, id);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   114
    }
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   115
  }
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   116
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   117
  const char* current_class_name() {
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   118
    return _class_name;
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   119
  }
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   120
48383
d6388b652504 8192989: runtime/appcds/javaldr/ArrayTest.java crashes with assert(k->is_instance_klass())
ccheung
parents: 48138
diff changeset
   121
  Klass* load_current_class(TRAPS);
48138
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   122
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   123
  bool is_loading_from_source();
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   124
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   125
  // Look up the super or interface of the current class being loaded
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   126
  // (in this->load_current_class()).
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   127
  InstanceKlass* lookup_super_for_current_class(Symbol* super_name);
78b2ecdd3c4b 8188791: Move AppCDS from closed repo to open repo
iklam
parents: 47216
diff changeset
   128
  InstanceKlass* lookup_interface_for_current_class(Symbol* interface_name);
34257
4be3504cc03b 8140802: Clean up and refactor of class loading code for CDS
iklam
parents:
diff changeset
   129
};
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52631
diff changeset
   130
#endif // SHARE_CLASSFILE_CLASSLISTPARSER_HPP