Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.hpp
32285 views
/*1* Copyright (c) 2005, 2013, 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_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP25#define SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP2627#include "jvmtifiles/jvmtiEnv.hpp"282930class JvmtiConstantPoolReconstituter : public StackObj {31private:32int _cpool_size;33SymbolHashMap* _symmap;34SymbolHashMap* _classmap;35constantPoolHandle _cpool;36instanceKlassHandle _ikh;37jvmtiError _err;3839protected:40instanceKlassHandle ikh() { return _ikh; };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(instanceKlassHandle ikh){55set_error(JVMTI_ERROR_NONE);56_ikh = ikh;57_cpool = constantPoolHandle(Thread::current(), ikh->constants());58_symmap = new SymbolHashMap();59_classmap = new SymbolHashMap();60_cpool_size = _cpool->hash_entries_to(_symmap, _classmap);61if (_cpool_size == 0) {62set_error(JVMTI_ERROR_OUT_OF_MEMORY);63} else if (_cpool_size < 0) {64set_error(JVMTI_ERROR_INTERNAL);65}66}6768~JvmtiConstantPoolReconstituter() {69if (_symmap != NULL) {70delete _symmap;71_symmap = NULL;72}73if (_classmap != NULL) {74delete _classmap;75_classmap = NULL;76}77}787980void set_error(jvmtiError err) { _err = err; }81jvmtiError get_error() { return _err; }8283int cpool_size() { return _cpool_size; }8485void copy_cpool_bytes(unsigned char *cpool_bytes) {86if (cpool_bytes == NULL) {87assert(cpool_bytes != NULL, "cpool_bytes pointer must not be NULL");88return;89}90cpool()->copy_cpool_bytes(cpool_size(), _symmap, cpool_bytes);91}92};939495class JvmtiClassFileReconstituter : public JvmtiConstantPoolReconstituter {96private:97size_t _buffer_size;98u1* _buffer;99u1* _buffer_ptr;100Thread* _thread;101102enum {103// initial size should be power of two104initial_buffer_size = 1024105};106107inline Thread* thread() { return _thread; }108109void write_class_file_format();110void write_field_infos();111void write_method_infos();112void write_method_info(methodHandle method);113void write_code_attribute(methodHandle method);114void write_exceptions_attribute(ConstMethod* const_method);115void write_synthetic_attribute();116void write_class_attributes();117void write_source_file_attribute();118void write_source_debug_extension_attribute();119u2 line_number_table_entries(methodHandle method);120void write_line_number_table_attribute(methodHandle method, u2 num_entries);121void write_local_variable_table_attribute(methodHandle method, u2 num_entries);122void write_local_variable_type_table_attribute(methodHandle method, u2 num_entries);123void write_stackmap_table_attribute(methodHandle method, int stackmap_table_len);124u2 inner_classes_attribute_length();125void write_inner_classes_attribute(int length);126void write_signature_attribute(u2 generic_signaure_index);127void write_attribute_name_index(const char* name);128void write_annotations_attribute(const char* attr_name, AnnotationArray* annos);129void write_bootstrapmethod_attribute();130131address writeable_address(size_t size);132void write_u1(u1 x);133void write_u2(u2 x);134void write_u4(u4 x);135void write_u8(u8 x);136137public:138// Calls to this constructor must be proceeded by a ResourceMark139// and a HandleMark140JvmtiClassFileReconstituter(instanceKlassHandle ikh) :141JvmtiConstantPoolReconstituter(ikh) {142_buffer_size = initial_buffer_size;143_buffer = _buffer_ptr = NEW_RESOURCE_ARRAY(u1, _buffer_size);144_thread = Thread::current();145write_class_file_format();146};147148size_t class_file_size() { return _buffer_ptr - _buffer; }149150u1* class_file_bytes() { return _buffer; }151152static void copy_bytecodes(methodHandle method, unsigned char* bytecodes);153};154155#endif // SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP156157158