Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/cds/classListParser.hpp
41144 views
1
/*
2
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_CDS_CLASSLISTPARSER_HPP
26
#define SHARE_CDS_CLASSLISTPARSER_HPP
27
28
#include "utilities/exceptions.hpp"
29
#include "utilities/globalDefinitions.hpp"
30
#include "utilities/growableArray.hpp"
31
#include "utilities/hashtable.inline.hpp"
32
33
#define LAMBDA_PROXY_TAG "@lambda-proxy"
34
#define LAMBDA_FORM_TAG "@lambda-form-invoker"
35
36
class Thread;
37
38
class CDSIndyInfo {
39
GrowableArray<const char*>* _items;
40
public:
41
CDSIndyInfo() : _items(NULL) {}
42
void add_item(const char* item) {
43
if (_items == NULL) {
44
_items = new GrowableArray<const char*>(9);
45
}
46
assert(_items != NULL, "sanity");
47
_items->append(item);
48
}
49
void add_ref_kind(int ref_kind) {
50
switch (ref_kind) {
51
case JVM_REF_getField : _items->append("REF_getField"); break;
52
case JVM_REF_getStatic : _items->append("REF_getStatic"); break;
53
case JVM_REF_putField : _items->append("REF_putField"); break;
54
case JVM_REF_putStatic : _items->append("REF_putStatic"); break;
55
case JVM_REF_invokeVirtual : _items->append("REF_invokeVirtual"); break;
56
case JVM_REF_invokeStatic : _items->append("REF_invokeStatic"); break;
57
case JVM_REF_invokeSpecial : _items->append("REF_invokeSpecial"); break;
58
case JVM_REF_newInvokeSpecial : _items->append("REF_newInvokeSpecial"); break;
59
case JVM_REF_invokeInterface : _items->append("REF_invokeInterface"); break;
60
default : ShouldNotReachHere();
61
}
62
}
63
GrowableArray<const char*>* items() {
64
return _items;
65
}
66
};
67
68
class ClassListParser : public StackObj {
69
typedef KVHashtable<int, InstanceKlass*, mtInternal> ID2KlassTable;
70
71
enum {
72
_unspecified = -999,
73
74
// Max number of bytes allowed per line in the classlist.
75
// Theoretically Java class names could be 65535 bytes in length. Also, an input line
76
// could have a very long path name up to JVM_MAXPATHLEN bytes in length. In reality,
77
// 4K bytes is more than enough.
78
_max_allowed_line_len = 4096,
79
_line_buf_extra = 10, // for detecting input too long
80
_line_buf_size = _max_allowed_line_len + _line_buf_extra
81
};
82
83
static const int INITIAL_TABLE_SIZE = 1987;
84
static volatile Thread* _parsing_thread; // the thread that created _instance
85
static ClassListParser* _instance; // the singleton.
86
const char* _classlist_file;
87
FILE* _file;
88
89
ID2KlassTable _id2klass_table;
90
91
// The following field contains information from the *current* line being
92
// parsed.
93
char _line[_line_buf_size]; // The buffer that holds the current line. Some characters in
94
// the buffer may be overwritten by '\0' during parsing.
95
int _line_len; // Original length of the input line.
96
int _line_no; // Line number for current line being parsed
97
const char* _class_name;
98
GrowableArray<const char*>* _indy_items; // items related to invoke dynamic for archiving lambda proxy classes
99
int _id;
100
int _super;
101
GrowableArray<int>* _interfaces;
102
bool _interfaces_specified;
103
const char* _source;
104
bool _lambda_form_line;
105
106
bool parse_int_option(const char* option_name, int* value);
107
bool parse_uint_option(const char* option_name, int* value);
108
InstanceKlass* load_class_from_source(Symbol* class_name, TRAPS);
109
ID2KlassTable* table() {
110
return &_id2klass_table;
111
}
112
InstanceKlass* lookup_class_by_id(int id);
113
void print_specified_interfaces();
114
void print_actual_interfaces(InstanceKlass *ik);
115
bool is_matching_cp_entry(constantPoolHandle &pool, int cp_index, TRAPS);
116
117
void resolve_indy(JavaThread* current, Symbol* class_name_symbol);
118
void resolve_indy_impl(Symbol* class_name_symbol, TRAPS);
119
bool parse_one_line();
120
Klass* load_current_class(Symbol* class_name_symbol, TRAPS);
121
122
public:
123
ClassListParser(const char* file);
124
~ClassListParser();
125
126
static bool is_parsing_thread();
127
static ClassListParser* instance() {
128
assert(is_parsing_thread(), "call this only in the thread that created ClassListParsing::_instance");
129
assert(_instance != NULL, "must be");
130
return _instance;
131
}
132
133
int parse(TRAPS);
134
void split_tokens_by_whitespace(int offset);
135
int split_at_tag_from_line();
136
bool parse_at_tags();
137
char* _token;
138
void error(const char* msg, ...);
139
void parse_int(int* value);
140
void parse_uint(int* value);
141
bool try_parse_uint(int* value);
142
bool skip_token(const char* option_name);
143
void skip_whitespaces();
144
void skip_non_whitespaces();
145
146
bool is_id_specified() {
147
return _id != _unspecified;
148
}
149
bool is_super_specified() {
150
return _super != _unspecified;
151
}
152
bool are_interfaces_specified() {
153
return _interfaces->length() > 0;
154
}
155
int id() {
156
assert(is_id_specified(), "do not query unspecified id");
157
return _id;
158
}
159
int super() {
160
assert(is_super_specified(), "do not query unspecified super");
161
return _super;
162
}
163
void check_already_loaded(const char* which, int id) {
164
if (_id2klass_table.lookup(id) == NULL) {
165
error("%s id %d is not yet loaded", which, id);
166
}
167
}
168
169
const char* current_class_name() {
170
return _class_name;
171
}
172
173
bool is_loading_from_source();
174
175
bool lambda_form_line() { return _lambda_form_line; }
176
177
// Look up the super or interface of the current class being loaded
178
// (in this->load_current_class()).
179
InstanceKlass* lookup_super_for_current_class(Symbol* super_name);
180
InstanceKlass* lookup_interface_for_current_class(Symbol* interface_name);
181
182
static void populate_cds_indy_info(const constantPoolHandle &pool, int cp_index, CDSIndyInfo* cii, TRAPS);
183
};
184
#endif // SHARE_CDS_CLASSLISTPARSER_HPP
185
186