< 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 ConstantPool::SymbolHash();
  45   _classmap = new ConstantPool::SymbolHash();
  46   _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);

 896 
 897 void JvmtiClassFileReconstituter::write_class_file_format() {
 898   ReallocMark();
 899 
 900   // JVMSpec|   ClassFile {
 901   // JVMSpec|           u4 magic;
 902   write_u4(0xCAFEBABE);
 903 
 904   // JVMSpec|           u2 minor_version;
 905   // JVMSpec|           u2 major_version;
 906   write_u2(ik()->minor_version());
 907   u2 major = ik()->major_version();
 908   write_u2(major);
 909 
 910   // JVMSpec|           u2 constant_pool_count;
 911   // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
 912   write_u2(cpool()->length());
 913   copy_cpool_bytes(writeable_address(cpool_size()));
 914 
 915   // JVMSpec|           u2 access_flags;
 916   write_u2(ik()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
 917 
 918   // JVMSpec|           u2 this_class;
 919   // JVMSpec|           u2 super_class;
 920   write_u2(class_symbol_to_cpool_index(ik()->name()));
 921   Klass* super_class = ik()->super();
 922   write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
 923                 class_symbol_to_cpool_index(super_class->name()));
 924 
 925   // JVMSpec|           u2 interfaces_count;
 926   // JVMSpec|           u2 interfaces[interfaces_count];
 927   Array<InstanceKlass*>* interfaces =  ik()->local_interfaces();
 928   int num_interfaces = interfaces->length();
 929   write_u2(num_interfaces);

 930   for (int index = 0; index < num_interfaces; index++) {
 931     HandleMark hm(thread());
 932     InstanceKlass* iik = interfaces->at(index);
 933     write_u2(class_symbol_to_cpool_index(iik->name()));
 934   }
 935 
 936   // JVMSpec|           u2 fields_count;
 937   // JVMSpec|           field_info fields[fields_count];
 938   write_field_infos();
 939 
 940   // JVMSpec|           u2 methods_count;
 941   // JVMSpec|           method_info methods[methods_count];
 942   write_method_infos();
 943 
 944   // JVMSpec|           u2 attributes_count;
 945   // JVMSpec|           attribute_info attributes[attributes_count];
 946   // JVMSpec|   } /* end ClassFile 8?
 947   write_class_attributes();
 948 }
 949 

1008     address bcp = bs.bcp();
1009     int     len = bs.instruction_size();
1010     assert(len > 0, "length must be > 0");
1011 
1012     // copy the bytecodes
1013     *p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code);
1014     if (len > 1) {
1015       memcpy(p+1, bcp+1, len-1);
1016     }
1017 
1018     // During linking the get/put and invoke instructions are rewritten
1019     // with an index into the constant pool cache. The original constant
1020     // pool index must be returned to caller.  Rewrite the index.
1021     if (is_rewritten && len > 1) {
1022       bool is_wide = false;
1023       switch (code) {
1024       case Bytecodes::_getstatic       :  // fall through
1025       case Bytecodes::_putstatic       :  // fall through
1026       case Bytecodes::_getfield        :  // fall through
1027       case Bytecodes::_putfield        :  // fall through

1028       case Bytecodes::_invokevirtual   :  // fall through
1029       case Bytecodes::_invokespecial   :  // fall through
1030       case Bytecodes::_invokestatic    :  // fall through
1031       case Bytecodes::_invokedynamic   :  // fall through
1032       case Bytecodes::_invokeinterface : {
1033         assert(len == 3 ||
1034                (code == Bytecodes::_invokeinterface && len == 5) ||
1035                (code == Bytecodes::_invokedynamic   && len == 5),
1036                "sanity check");
1037 
1038         int cpci = Bytes::get_native_u2(bcp+1);
1039         bool is_invokedynamic = (code == Bytecodes::_invokedynamic);
1040         ConstantPoolCacheEntry* entry;
1041         if (is_invokedynamic) {
1042           cpci = Bytes::get_native_u4(bcp+1);
1043           entry = mh->constants()->invokedynamic_cp_cache_entry_at(cpci);
1044         } else {
1045         // cache cannot be pre-fetched since some classes won't have it yet
1046           entry = mh->constants()->cache()->entry_at(cpci);
1047         }

   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 ConstantPool::SymbolHash();
  46   _classmap = new ConstantPool::SymbolHash();
  47   _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);

 897 
 898 void JvmtiClassFileReconstituter::write_class_file_format() {
 899   ReallocMark();
 900 
 901   // JVMSpec|   ClassFile {
 902   // JVMSpec|           u4 magic;
 903   write_u4(0xCAFEBABE);
 904 
 905   // JVMSpec|           u2 minor_version;
 906   // JVMSpec|           u2 major_version;
 907   write_u2(ik()->minor_version());
 908   u2 major = ik()->major_version();
 909   write_u2(major);
 910 
 911   // JVMSpec|           u2 constant_pool_count;
 912   // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
 913   write_u2(cpool()->length());
 914   copy_cpool_bytes(writeable_address(cpool_size()));
 915 
 916   // JVMSpec|           u2 access_flags;
 917   write_u2(ik()->access_flags().get_flags() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIMITIVE | JVM_ACC_VALUE | JVM_ACC_IDENTITY));

 918   // JVMSpec|           u2 this_class;
 919   // JVMSpec|           u2 super_class;
 920   write_u2(class_symbol_to_cpool_index(ik()->name()));
 921   Klass* super_class = ik()->super();
 922   write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
 923                 class_symbol_to_cpool_index(super_class->name()));
 924 
 925   // JVMSpec|           u2 interfaces_count;
 926   // JVMSpec|           u2 interfaces[interfaces_count];
 927   Array<InstanceKlass*>* interfaces =  ik()->local_interfaces();
 928   int num_interfaces = interfaces->length();
 929   write_u2(num_interfaces);
 930 
 931   for (int index = 0; index < num_interfaces; index++) {
 932     HandleMark hm(thread());
 933     InstanceKlass* iik = interfaces->at(index);
 934     write_u2(class_symbol_to_cpool_index(iik->name()));
 935   }
 936 
 937   // JVMSpec|           u2 fields_count;
 938   // JVMSpec|           field_info fields[fields_count];
 939   write_field_infos();
 940 
 941   // JVMSpec|           u2 methods_count;
 942   // JVMSpec|           method_info methods[methods_count];
 943   write_method_infos();
 944 
 945   // JVMSpec|           u2 attributes_count;
 946   // JVMSpec|           attribute_info attributes[attributes_count];
 947   // JVMSpec|   } /* end ClassFile 8?
 948   write_class_attributes();
 949 }
 950 

1009     address bcp = bs.bcp();
1010     int     len = bs.instruction_size();
1011     assert(len > 0, "length must be > 0");
1012 
1013     // copy the bytecodes
1014     *p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code);
1015     if (len > 1) {
1016       memcpy(p+1, bcp+1, len-1);
1017     }
1018 
1019     // During linking the get/put and invoke instructions are rewritten
1020     // with an index into the constant pool cache. The original constant
1021     // pool index must be returned to caller.  Rewrite the index.
1022     if (is_rewritten && len > 1) {
1023       bool is_wide = false;
1024       switch (code) {
1025       case Bytecodes::_getstatic       :  // fall through
1026       case Bytecodes::_putstatic       :  // fall through
1027       case Bytecodes::_getfield        :  // fall through
1028       case Bytecodes::_putfield        :  // fall through
1029       case Bytecodes::_withfield       :  // fall through
1030       case Bytecodes::_invokevirtual   :  // fall through
1031       case Bytecodes::_invokespecial   :  // fall through
1032       case Bytecodes::_invokestatic    :  // fall through
1033       case Bytecodes::_invokedynamic   :  // fall through
1034       case Bytecodes::_invokeinterface : {
1035         assert(len == 3 ||
1036                (code == Bytecodes::_invokeinterface && len == 5) ||
1037                (code == Bytecodes::_invokedynamic   && len == 5),
1038                "sanity check");
1039 
1040         int cpci = Bytes::get_native_u2(bcp+1);
1041         bool is_invokedynamic = (code == Bytecodes::_invokedynamic);
1042         ConstantPoolCacheEntry* entry;
1043         if (is_invokedynamic) {
1044           cpci = Bytes::get_native_u4(bcp+1);
1045           entry = mh->constants()->invokedynamic_cp_cache_entry_at(cpci);
1046         } else {
1047         // cache cannot be pre-fetched since some classes won't have it yet
1048           entry = mh->constants()->cache()->entry_at(cpci);
1049         }
< prev index next >