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