hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp
author kamg
Mon, 06 Dec 2010 20:21:15 -0500
changeset 7413 59b978f8fbdf
parent 7397 5b173b4ca846
child 8076 96d498ec7ae1
permissions -rw-r--r--
7003782: Update JVMTI version to 1.2 for jdk7 Summary: Update minor version to 1.2 for jdk7 Reviewed-by: phh, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
5702
jrose
parents: 5547 5688
diff changeset
     2
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    26
#include "classfile/symbolTable.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    27
#include "interpreter/bytecodeStream.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    28
#include "prims/jvmtiClassFileReconstituter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    29
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    31
# include "bytes_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    32
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    33
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    34
# include "bytes_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    35
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    36
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    37
# include "bytes_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    38
#endif
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// FIXME: add Deprecated, LVT, LVTT attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// FIXME: fix Synthetic attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// FIXME: per Serguei, add error return handling for constantPoolOopDesc::copy_cpool_bytes()
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// Write the field information portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// JVMSpec|     u2 fields_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// JVMSpec|     field_info fields[fields_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
void JvmtiClassFileReconstituter::write_field_infos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  HandleMark hm(thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  typeArrayHandle fields(thread(), ikh()->fields());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  int fields_length = fields->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  int num_fields = fields_length / instanceKlass::next_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  objArrayHandle fields_anno(thread(), ikh()->fields_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  write_u2(num_fields);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  for (int index = 0; index < fields_length; index += instanceKlass::next_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    AccessFlags access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    int flags = fields->ushort_at(index + instanceKlass::access_flags_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    access_flags.set_flags(flags);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    int name_index = fields->ushort_at(index + instanceKlass::name_index_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    int signature_index = fields->ushort_at(index + instanceKlass::signature_index_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    int initial_value_index = fields->ushort_at(index + instanceKlass::initval_index_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    int offset = ikh()->offset_from_fields( index );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    int generic_signature_index =
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                        fields->ushort_at(index + instanceKlass::generic_signature_offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    typeArrayHandle anno(thread(), fields_anno.not_null() ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
                                 (typeArrayOop)(fields_anno->obj_at(index / instanceKlass::next_offset)) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
                                 (typeArrayOop)NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    // JVMSpec|   field_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    // JVMSpec|         u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // JVMSpec|         u2 name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    // JVMSpec|         u2 descriptor_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // JVMSpec|         u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    // JVMSpec|         attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    // JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    write_u2(flags & JVM_RECOGNIZED_FIELD_MODIFIERS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
    write_u2(name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    write_u2(signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (initial_value_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
      // ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
      ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    if (initial_value_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
      write_attribute_name_index("ConstantValue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
      write_u4(2); //length always 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      write_u2(initial_value_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
      // write_synthetic_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
      write_signature_attribute(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// Write Code attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
// JVMSpec|   Code_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// JVMSpec|     u2 max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// JVMSpec|     u2 max_locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// JVMSpec|     u4 code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// JVMSpec|     u1 code[code_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// JVMSpec|     u2 exception_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// JVMSpec|     {       u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// JVMSpec|             u2 end_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// JVMSpec|             u2  handler_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// JVMSpec|             u2  catch_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// JVMSpec|     }       exception_table[exception_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
void JvmtiClassFileReconstituter::write_code_attribute(methodHandle method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  constMethodHandle const_method(thread(), method->constMethod());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  u2 line_num_cnt = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  int stackmap_len = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // compute number and length of attributes -- FIXME: for now no LVT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  int attr_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  if (const_method->has_linenumber_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    line_num_cnt = line_number_table_entries(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    if (line_num_cnt != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      // Compute the complete size of the line number table attribute:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      //      LineNumberTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      //        u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      //        u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      //        u2 line_number_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      //        {  u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      //           u2 line_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      //        } line_number_table[line_number_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      attr_size += 2 + 4 + 2 + line_num_cnt * (2 + 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  if (method->has_stackmap_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    stackmap_len = method->stackmap_data()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    if (stackmap_len != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
      // Compute the  size of the stack map table attribute (VM stores raw):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
      //      StackMapTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
      //        u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      //        u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      //        u2 number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      //        stack_map_frame_entries[number_of_entries];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      attr_size += 2 + 4 + stackmap_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  typeArrayHandle exception_table(thread(), const_method->exception_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  int exception_table_length = exception_table->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  int exception_table_entries = exception_table_length / 4;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  int code_size = const_method->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  int size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    2+2+4 +                                // max_stack, max_locals, code_length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    code_size +                            // code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    2 +                                    // exception_table_length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
    (2+2+2+2) * exception_table_entries +  // exception_table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    2 +                                    // attributes_count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    attr_size;                             // attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  write_attribute_name_index("Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  write_u2(method->max_stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  write_u2(method->max_locals());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  write_u4(code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  copy_bytecodes(method, (unsigned char*)writeable_address(code_size));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  write_u2(exception_table_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  for (int index = 0; index < exception_table_length; ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
    write_u2(exception_table->int_at(index++));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    write_u2(exception_table->int_at(index++));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
    write_u2(exception_table->int_at(index++));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    write_u2(exception_table->int_at(index++));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  if (line_num_cnt != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    write_line_number_table_attribute(method, line_num_cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  if (stackmap_len != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    write_stackmap_table_attribute(method, stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  // FIXME: write LVT attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
// Write Exceptions attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
// JVMSpec|   Exceptions_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
// JVMSpec|     u2 number_of_exceptions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
// JVMSpec|     u2 exception_index_table[number_of_exceptions];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
void JvmtiClassFileReconstituter::write_exceptions_attribute(constMethodHandle const_method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  int checked_exceptions_length = const_method->checked_exceptions_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  int size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
    2 +                                    // number_of_exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    2 * checked_exceptions_length;         // exception_index_table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  write_attribute_name_index("Exceptions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  write_u2(checked_exceptions_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  for (int index = 0; index < checked_exceptions_length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    write_u2(checked_exceptions[index].class_cp_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
// Write SourceFile attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
// JVMSpec|   SourceFile_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
// JVMSpec|     u2 sourcefile_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
void JvmtiClassFileReconstituter::write_source_file_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  assert(ikh()->source_file_name() != NULL, "caller must check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  write_attribute_name_index("SourceFile");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  write_u4(2);  // always length 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  write_u2(symbol_to_cpool_index(ikh()->source_file_name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// Write SourceDebugExtension attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
// JSR45|   SourceDebugExtension_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
// JSR45|       u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
// JSR45|       u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
// JSR45|       u2 sourcefile_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
// JSR45|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
void JvmtiClassFileReconstituter::write_source_debug_extension_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert(ikh()->source_debug_extension() != NULL, "caller must check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  write_attribute_name_index("SourceDebugExtension");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  write_u4(2);  // always length 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  write_u2(symbol_to_cpool_index(ikh()->source_debug_extension()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
// Write (generic) Signature attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
// JVMSpec|   Signature_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
// JVMSpec|     u2 signature_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  write_attribute_name_index("Signature");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  write_u4(2);  // always length 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  write_u2(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
// Compute the number of entries in the InnerClasses attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  typeArrayOop inner_class_list = ikh()->inner_classes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  return (inner_class_list == NULL) ? 0 : inner_class_list->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
// Write an annotation attribute.  The VM stores them in raw form, so all we need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
// to do is add the attrubute name and fill in the length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
// JSR202|   *Annotations_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
// JSR202|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
// JSR202|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
// JSR202|     ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
// JSR202|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
void JvmtiClassFileReconstituter::write_annotations_attribute(const char* attr_name,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
                                                              typeArrayHandle annos) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  u4 length = annos->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  write_attribute_name_index(attr_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  write_u4(length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  memcpy(writeable_address(length), annos->byte_at_addr(0), length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
// Write InnerClasses attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
// JVMSpec|   InnerClasses_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
// JVMSpec|     u2 number_of_classes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
// JVMSpec|     {  u2 inner_class_info_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// JVMSpec|        u2 outer_class_info_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
// JVMSpec|        u2 inner_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
// JVMSpec|        u2 inner_class_access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
// JVMSpec|     } classes[number_of_classes];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  typeArrayOop inner_class_list = ikh()->inner_classes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  guarantee(inner_class_list != NULL && inner_class_list->length() == length,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
            "caller must check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  typeArrayHandle inner_class_list_h(thread(), inner_class_list);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  assert (length % instanceKlass::inner_class_next_offset == 0, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  u2 entry_count = length / instanceKlass::inner_class_next_offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  u4 size = 2 + entry_count * (2+2+2+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  write_attribute_name_index("InnerClasses");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  write_u2(entry_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  for (int i = 0; i < length; i += instanceKlass::inner_class_next_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
    write_u2(inner_class_list_h->ushort_at(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
                      i + instanceKlass::inner_class_inner_class_info_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
    write_u2(inner_class_list_h->ushort_at(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
                      i + instanceKlass::inner_class_outer_class_info_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
    write_u2(inner_class_list_h->ushort_at(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
                      i + instanceKlass::inner_class_inner_name_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    write_u2(inner_class_list_h->ushort_at(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
                      i + instanceKlass::inner_class_access_flags_offset));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
// Write Synthetic attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
// JVMSpec|   Synthetic_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
void JvmtiClassFileReconstituter::write_synthetic_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  write_attribute_name_index("Synthetic");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
  write_u4(0); //length always zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
// Compute size of LineNumberTable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
u2 JvmtiClassFileReconstituter::line_number_table_entries(methodHandle method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  // The line number table is compressed so we don't know how big it is until decompressed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  // Decompression is really fast so we just do it twice.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  u2 num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  while (stream.read_pair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
// Write LineNumberTable attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
// JVMSpec|   LineNumberTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
// JVMSpec|     u2 line_number_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
// JVMSpec|     {  u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
// JVMSpec|        u2 line_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
// JVMSpec|     } line_number_table[line_number_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
void JvmtiClassFileReconstituter::write_line_number_table_attribute(methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
                                                                    u2 num_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  write_attribute_name_index("LineNumberTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  write_u4(2 + num_entries * (2 + 2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  write_u2(num_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  while (stream.read_pair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    write_u2(stream.bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
    write_u2(stream.line());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
// Write stack map table attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
// JSR-202|   StackMapTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
// JSR-202|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
// JSR-202|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// JSR-202|     u2 number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// JSR-202|     stack_map_frame_entries[number_of_entries];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// JSR-202|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
void JvmtiClassFileReconstituter::write_stackmap_table_attribute(methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
                                                                 int stackmap_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  write_attribute_name_index("StackMapTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  write_u4(stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  memcpy(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
    writeable_address(stackmap_len),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
    (void*)(method->stackmap_data()->byte_at_addr(0)),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
    stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
// Write one method_info structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
// JVMSpec|   method_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
// JVMSpec|     u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// JVMSpec|     u2 name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// JVMSpec|     u2 descriptor_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  AccessFlags access_flags = method->access_flags();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  constMethodHandle const_method(thread(), method->constMethod());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  u2 generic_signature_index = const_method->generic_signature_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  typeArrayHandle anno(thread(), method->annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  typeArrayHandle param_anno(thread(), method->parameter_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  typeArrayHandle default_anno(thread(), method->annotation_default());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  write_u2(const_method->name_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  write_u2(const_method->signature_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // write attributes in the same order javac does, so we can test with byte for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // byte comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  if (const_method->code_size() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
    ++attr_count;     // has Code attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  if (const_method->has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    ++attr_count;     // has Exceptions attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  if (default_anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
    ++attr_count;     // has AnnotationDefault attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // Deprecated attribute would go here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  if (access_flags.is_synthetic()) { // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    // ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
  if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  if (param_anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
  if (const_method->code_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    write_code_attribute(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
  if (const_method->has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    write_exceptions_attribute(const_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  if (default_anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
    write_annotations_attribute("AnnotationDefault", default_anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  // Deprecated attribute would go here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
    // write_synthetic_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
    write_signature_attribute(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  if (param_anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
// Write the class attributes portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
void JvmtiClassFileReconstituter::write_class_attributes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  u2 inner_classes_length = inner_classes_attribute_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  symbolHandle generic_signature(thread(), ikh()->generic_signature());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  typeArrayHandle anno(thread(), ikh()->class_annotations());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  if (generic_signature() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  if (ikh()->source_file_name() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
  if (ikh()->source_debug_extension() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
  if (inner_classes_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  if (generic_signature() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    write_signature_attribute(symbol_to_cpool_index(generic_signature()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  if (ikh()->source_file_name() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
    write_source_file_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  if (ikh()->source_debug_extension() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
    write_source_debug_extension_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  if (inner_classes_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    write_inner_classes_attribute(inner_classes_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  if (anno.not_null()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
// Write the method information portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
// JVMSpec|     u2 methods_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
// JVMSpec|     method_info methods[methods_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
void JvmtiClassFileReconstituter::write_method_infos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
  HandleMark hm(thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
  objArrayHandle methods(thread(), ikh()->methods());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  int num_methods = methods->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  write_u2(num_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
  if (JvmtiExport::can_maintain_original_method_order()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
    int original_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
    int* method_order = NEW_RESOURCE_ARRAY(int, num_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
    // invert the method order mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
    for (index = 0; index < num_methods; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
      original_index = ikh()->method_ordering()->int_at(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      assert(original_index >= 0 && original_index < num_methods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
             "invalid original method index");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
      method_order[original_index] = index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    // write in original order
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
    for (original_index = 0; original_index < num_methods; original_index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
      index = method_order[original_index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
      methodHandle method(thread(), (methodOop)(ikh()->methods()->obj_at(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
      write_method_info(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    // method order not preserved just dump the method infos
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
    for (int index = 0; index < num_methods; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      methodHandle method(thread(), (methodOop)(ikh()->methods()->obj_at(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      write_method_info(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
void JvmtiClassFileReconstituter::write_class_file_format() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  ReallocMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // JVMSpec|   ClassFile {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  // JVMSpec|           u4 magic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
  write_u4(0xCAFEBABE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  // JVMSpec|           u2 minor_version;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // JVMSpec|           u2 major_version;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  write_u2(ikh()->minor_version());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  u2 major = ikh()->major_version();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  write_u2(major);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
  // JVMSpec|           u2 constant_pool_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
  // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  write_u2(cpool()->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  copy_cpool_bytes(writeable_address(cpool_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  // JVMSpec|           u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  write_u2(ikh()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
  // JVMSpec|           u2 this_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // JVMSpec|           u2 super_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  write_u2(class_symbol_to_cpool_index(ikh()->name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
  klassOop super_class = ikh()->super();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
                class_symbol_to_cpool_index(super_class->klass_part()->name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  // JVMSpec|           u2 interfaces_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
  // JVMSpec|           u2 interfaces[interfaces_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
  objArrayHandle interfaces(thread(), ikh()->local_interfaces());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
  int num_interfaces = interfaces->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
  write_u2(num_interfaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
  for (int index = 0; index < num_interfaces; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
    HandleMark hm(thread());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
    instanceKlassHandle iikh(thread(), klassOop(interfaces->obj_at(index)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
    write_u2(class_symbol_to_cpool_index(iikh->name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  // JVMSpec|           u2 fields_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
  // JVMSpec|           field_info fields[fields_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  write_field_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  // JVMSpec|           u2 methods_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // JVMSpec|           method_info methods[methods_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  write_method_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
  // JVMSpec|           u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  // JVMSpec|           attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  // JVMSpec|   } /* end ClassFile 8?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
  write_class_attributes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
address JvmtiClassFileReconstituter::writeable_address(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  size_t used_size = _buffer_ptr - _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  if (size + used_size >= _buffer_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
    // compute the new buffer size: must be at least twice as big as before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
    // plus whatever new is being used; then convert to nice clean block boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
    size_t new_buffer_size = (size + _buffer_size*2 + 1) / initial_buffer_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
                                                         * initial_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    // VM goes belly-up if the memory isn't available, so cannot do OOM processing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    _buffer = REALLOC_RESOURCE_ARRAY(u1, _buffer, _buffer_size, new_buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
    _buffer_size = new_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    _buffer_ptr = _buffer + used_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  u1* ret_ptr = _buffer_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  _buffer_ptr += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
  return ret_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
void JvmtiClassFileReconstituter::write_attribute_name_index(const char* name) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  unsigned int hash_ignored;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
  symbolOop sym = SymbolTable::lookup_only(name, (int)strlen(name), hash_ignored);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
  assert(sym != NULL, "attribute name symbol not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
  u2 attr_name_index = symbol_to_cpool_index(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
  assert(attr_name_index != 0, "attribute name symbol not in constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
  write_u2(attr_name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
void JvmtiClassFileReconstituter::write_u1(u1 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  *writeable_address(1) = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
void JvmtiClassFileReconstituter::write_u2(u2 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
  Bytes::put_Java_u2(writeable_address(2), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
void JvmtiClassFileReconstituter::write_u4(u4 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
  Bytes::put_Java_u4(writeable_address(4), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
void JvmtiClassFileReconstituter::write_u8(u8 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  Bytes::put_Java_u8(writeable_address(8), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
void JvmtiClassFileReconstituter::copy_bytecodes(methodHandle mh,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
                                                 unsigned char* bytecodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
  // use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
  // and the breakpoint bytecode are converted to their original bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  BytecodeStream bs(mh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  unsigned char* p = bytecodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
  Bytecodes::Code code;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
  bool is_rewritten = instanceKlass::cast(mh->method_holder())->is_rewritten();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  while ((code = bs.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    assert(Bytecodes::is_java_code(code), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    assert(code != Bytecodes::_breakpoint, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    // length of bytecode (mnemonic + operands)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
    address bcp = bs.bcp();
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   653
    int     len = bs.instruction_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
    assert(len > 0, "length must be > 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
    // copy the bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
    *p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
    if (len > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
      memcpy(p+1, bcp+1, len-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
    // During linking the get/put and invoke instructions are rewritten
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
    // with an index into the constant pool cache. The original constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    // pool index must be returned to caller.  Rewrite the index.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
    if (is_rewritten && len >= 3) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
      switch (code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
      case Bytecodes::_getstatic       :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
      case Bytecodes::_putstatic       :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
      case Bytecodes::_getfield        :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
      case Bytecodes::_putfield        :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
      case Bytecodes::_invokevirtual   :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
      case Bytecodes::_invokespecial   :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
      case Bytecodes::_invokestatic    :  // fall through
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   674
      case Bytecodes::_invokedynamic   :  // fall through
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
      case Bytecodes::_invokeinterface :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
        assert(len == 3 || (code == Bytecodes::_invokeinterface && len ==5),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
               "sanity check");
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   678
        int cpci = Bytes::get_native_u2(bcp+1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   679
        bool is_invokedynamic = (EnableInvokeDynamic && code == Bytecodes::_invokedynamic);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   680
        if (is_invokedynamic)
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   681
          cpci = Bytes::get_native_u4(bcp+1);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
        // cache cannot be pre-fetched since some classes won't have it yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        ConstantPoolCacheEntry* entry =
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   684
          mh->constants()->cache()->main_entry_at(cpci);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
        int i = entry->constant_pool_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
        assert(i < mh->constants()->length(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
        Bytes::put_Java_u2((address)(p+1), (u2)i);     // java byte ordering
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   688
        if (is_invokedynamic)  *(p+3) = *(p+4) = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    p += len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
}