< prev index next >

src/hotspot/share/prims/jvmtiClassFileReconstituter.cpp

Print this page

   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 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"

  27 #include "interpreter/bytecodeStream.hpp"
  28 #include "memory/universe.hpp"
  29 #include "oops/fieldStreams.inline.hpp"
  30 #include "oops/recordComponent.hpp"
  31 #include "prims/jvmtiClassFileReconstituter.hpp"
  32 #include "runtime/handles.inline.hpp"
  33 #include "runtime/signature.hpp"
  34 #include "utilities/bytes.hpp"
  35 
  36 // FIXME: add Deprecated attribute
  37 // FIXME: fix Synthetic attribute
  38 // FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
  39 
  40 JvmtiConstantPoolReconstituter::JvmtiConstantPoolReconstituter(InstanceKlass* ik) {
  41   set_error(JVMTI_ERROR_NONE);
  42   _ik = ik;
  43   _cpool = constantPoolHandle(Thread::current(), ik->constants());
  44   _symmap = new SymbolHashMap();
  45   _classmap = new SymbolHashMap();
  46   _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);

 878 
 879   // JVMSpec|           u2 constant_pool_count;
 880   // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
 881   write_u2(cpool()->length());
 882   copy_cpool_bytes(writeable_address(cpool_size()));
 883 
 884   // JVMSpec|           u2 access_flags;
 885   write_u2(ik()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
 886 
 887   // JVMSpec|           u2 this_class;
 888   // JVMSpec|           u2 super_class;
 889   write_u2(class_symbol_to_cpool_index(ik()->name()));
 890   Klass* super_class = ik()->super();
 891   write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
 892                 class_symbol_to_cpool_index(super_class->name()));
 893 
 894   // JVMSpec|           u2 interfaces_count;
 895   // JVMSpec|           u2 interfaces[interfaces_count];
 896   Array<InstanceKlass*>* interfaces =  ik()->local_interfaces();
 897   int num_interfaces = interfaces->length();
 898   write_u2(num_interfaces);


 899   for (int index = 0; index < num_interfaces; index++) {
 900     HandleMark hm(thread());
 901     InstanceKlass* iik = interfaces->at(index);
 902     write_u2(class_symbol_to_cpool_index(iik->name()));



 903   }
 904 
 905   // JVMSpec|           u2 fields_count;
 906   // JVMSpec|           field_info fields[fields_count];
 907   write_field_infos();
 908 
 909   // JVMSpec|           u2 methods_count;
 910   // JVMSpec|           method_info methods[methods_count];
 911   write_method_infos();
 912 
 913   // JVMSpec|           u2 attributes_count;
 914   // JVMSpec|           attribute_info attributes[attributes_count];
 915   // JVMSpec|   } /* end ClassFile 8?
 916   write_class_attributes();
 917 }
 918 
 919 address JvmtiClassFileReconstituter::writeable_address(size_t size) {
 920   size_t used_size = _buffer_ptr - _buffer;
 921   if (size + used_size >= _buffer_size) {
 922     // compute the new buffer size: must be at least twice as big as before

   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 #include "precompiled.hpp"
  26 #include "classfile/symbolTable.hpp"
  27 #include "classfile/vmClasses.hpp"
  28 #include "interpreter/bytecodeStream.hpp"
  29 #include "memory/universe.hpp"
  30 #include "oops/fieldStreams.inline.hpp"
  31 #include "oops/recordComponent.hpp"
  32 #include "prims/jvmtiClassFileReconstituter.hpp"
  33 #include "runtime/handles.inline.hpp"
  34 #include "runtime/signature.hpp"
  35 #include "utilities/bytes.hpp"
  36 
  37 // FIXME: add Deprecated attribute
  38 // FIXME: fix Synthetic attribute
  39 // FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
  40 
  41 JvmtiConstantPoolReconstituter::JvmtiConstantPoolReconstituter(InstanceKlass* ik) {
  42   set_error(JVMTI_ERROR_NONE);
  43   _ik = ik;
  44   _cpool = constantPoolHandle(Thread::current(), ik->constants());
  45   _symmap = new SymbolHashMap();
  46   _classmap = new SymbolHashMap();
  47   _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);

 879 
 880   // JVMSpec|           u2 constant_pool_count;
 881   // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
 882   write_u2(cpool()->length());
 883   copy_cpool_bytes(writeable_address(cpool_size()));
 884 
 885   // JVMSpec|           u2 access_flags;
 886   write_u2(ik()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
 887 
 888   // JVMSpec|           u2 this_class;
 889   // JVMSpec|           u2 super_class;
 890   write_u2(class_symbol_to_cpool_index(ik()->name()));
 891   Klass* super_class = ik()->super();
 892   write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
 893                 class_symbol_to_cpool_index(super_class->name()));
 894 
 895   // JVMSpec|           u2 interfaces_count;
 896   // JVMSpec|           u2 interfaces[interfaces_count];
 897   Array<InstanceKlass*>* interfaces =  ik()->local_interfaces();
 898   int num_interfaces = interfaces->length();
 899   write_u2(num_interfaces -
 900            (ik()->has_injected_identityObject() || ik()->has_injected_primitiveObject() ? 1 : 0));
 901 
 902   for (int index = 0; index < num_interfaces; index++) {
 903     HandleMark hm(thread());
 904     InstanceKlass* iik = interfaces->at(index);
 905     if ( (!ik()->has_injected_identityObject() || iik != vmClasses::IdentityObject_klass()) &&
 906          (!ik()->has_injected_primitiveObject() || iik != vmClasses::PrimitiveObject_klass())) {
 907       write_u2(class_symbol_to_cpool_index(iik->name()));
 908     }
 909   }
 910 
 911   // JVMSpec|           u2 fields_count;
 912   // JVMSpec|           field_info fields[fields_count];
 913   write_field_infos();
 914 
 915   // JVMSpec|           u2 methods_count;
 916   // JVMSpec|           method_info methods[methods_count];
 917   write_method_infos();
 918 
 919   // JVMSpec|           u2 attributes_count;
 920   // JVMSpec|           attribute_info attributes[attributes_count];
 921   // JVMSpec|   } /* end ClassFile 8?
 922   write_class_attributes();
 923 }
 924 
 925 address JvmtiClassFileReconstituter::writeable_address(size_t size) {
 926   size_t used_size = _buffer_ptr - _buffer;
 927   if (size + used_size >= _buffer_size) {
 928     // compute the new buffer size: must be at least twice as big as before
< prev index next >