Path: blob/master/src/hotspot/share/prims/jvmtiClassFileReconstituter.hpp
41144 views
/*1* Copyright (c) 2005, 2020, 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_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP25#define SHARE_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP2627#include "jvmtifiles/jvmtiEnv.hpp"282930class JvmtiConstantPoolReconstituter : public StackObj {31private:32int _cpool_size;33SymbolHashMap* _symmap;34SymbolHashMap* _classmap;35constantPoolHandle _cpool;36InstanceKlass* _ik;37jvmtiError _err;3839protected:40InstanceKlass* ik() { return _ik; };41constantPoolHandle cpool() { return _cpool; };4243u2 symbol_to_cpool_index(Symbol* sym) {44return _symmap->symbol_to_value(sym);45}4647u2 class_symbol_to_cpool_index(Symbol* sym) {48return _classmap->symbol_to_value(sym);49}5051public:52// Calls to this constructor must be proceeded by a ResourceMark53// and a HandleMark54JvmtiConstantPoolReconstituter(InstanceKlass* ik);5556~JvmtiConstantPoolReconstituter() {57if (_symmap != NULL) {58delete _symmap;59_symmap = NULL;60}61if (_classmap != NULL) {62delete _classmap;63_classmap = NULL;64}65}666768void set_error(jvmtiError err) { _err = err; }69jvmtiError get_error() { return _err; }7071int cpool_size() { return _cpool_size; }7273void copy_cpool_bytes(unsigned char *cpool_bytes) {74if (cpool_bytes == NULL) {75assert(cpool_bytes != NULL, "cpool_bytes pointer must not be NULL");76return;77}78cpool()->copy_cpool_bytes(cpool_size(), _symmap, cpool_bytes);79}80};818283class JvmtiClassFileReconstituter : public JvmtiConstantPoolReconstituter {84private:85size_t _buffer_size;86u1* _buffer;87u1* _buffer_ptr;88Thread* _thread;8990enum {91// initial size should be power of two92initial_buffer_size = 102493};9495inline Thread* thread() { return _thread; }9697void write_class_file_format();98void write_field_infos();99void write_method_infos();100void write_method_info(const methodHandle& method);101void write_code_attribute(const methodHandle& method);102void write_exceptions_attribute(ConstMethod* const_method);103void write_synthetic_attribute();104void write_class_attributes();105void write_source_file_attribute();106void write_source_debug_extension_attribute();107u2 line_number_table_entries(const methodHandle& method);108void write_line_number_table_attribute(const methodHandle& method, u2 num_entries);109void write_local_variable_table_attribute(const methodHandle& method, u2 num_entries);110void write_local_variable_type_table_attribute(const methodHandle& method, u2 num_entries);111void write_stackmap_table_attribute(const methodHandle& method, int stackmap_table_len);112u2 inner_classes_attribute_length();113void write_inner_classes_attribute(int length);114void write_signature_attribute(u2 generic_signaure_index);115void write_attribute_name_index(const char* name);116void write_annotations_attribute(const char* attr_name, AnnotationArray* annos);117void write_bootstrapmethod_attribute();118void write_nest_host_attribute();119void write_nest_members_attribute();120void write_permitted_subclasses_attribute();121void write_record_attribute();122123address writeable_address(size_t size);124void write_u1(u1 x);125void write_u2(u2 x);126void write_u4(u4 x);127void write_u8(u8 x);128129public:130// Calls to this constructor must be proceeded by a ResourceMark131// and a HandleMark132JvmtiClassFileReconstituter(InstanceKlass* ik) :133JvmtiConstantPoolReconstituter(ik) {134_buffer_size = initial_buffer_size;135_buffer = _buffer_ptr = NEW_RESOURCE_ARRAY(u1, _buffer_size);136_thread = Thread::current();137write_class_file_format();138};139140size_t class_file_size() { return _buffer_ptr - _buffer; }141142u1* class_file_bytes() { return _buffer; }143144static void copy_bytecodes(const methodHandle& method, unsigned char* bytecodes);145};146147#endif // SHARE_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP148149150