hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.cpp
author stefank
Mon, 01 Oct 2012 13:29:11 +0200
changeset 13922 ab7d352debe6
parent 13863 3a6dfc8fdfd1
child 14391 df0a1573d5bd
child 14480 06c1743f1285
permissions -rw-r--r--
8000227: [obj|type]ArrayKlass::oop_print_on prints one line to tty instead of the provided output stream Reviewed-by: brutisso, sla, jmasa, coleenp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
12102
7a1c6c80bc23 7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents: 11257
diff changeset
     2
 * Copyright (c) 2005, 2012, 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"
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    28
#include "oops/fieldStreams.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    29
#include "prims/jvmtiClassFileReconstituter.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    30
#include "runtime/signature.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    31
#ifdef TARGET_ARCH_x86
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    32
# include "bytes_x86.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    33
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    34
#ifdef TARGET_ARCH_sparc
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    35
# include "bytes_sparc.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    36
#endif
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    37
#ifdef TARGET_ARCH_zero
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    38
# include "bytes_zero.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5702
diff changeset
    39
#endif
8107
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    40
#ifdef TARGET_ARCH_arm
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    41
# include "bytes_arm.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    42
#endif
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    43
#ifdef TARGET_ARCH_ppc
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    44
# include "bytes_ppc.hpp"
78e5bd944384 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 8076
diff changeset
    45
#endif
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
    46
// FIXME: add Deprecated attribute
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// FIXME: fix Synthetic attribute
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
    48
// FIXME: per Serguei, add error return handling for ConstantPool::copy_cpool_bytes()
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// Write the field information portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// JVMSpec|     u2 fields_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
// JVMSpec|     field_info fields[fields_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
void JvmtiClassFileReconstituter::write_field_infos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  HandleMark hm(thread());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
    56
  Array<AnnotationArray*>* fields_anno = ikh()->fields_annotations();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    58
  // Compute the real number of Java fields
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    59
  int java_fields = ikh()->java_fields_count();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    60
10552
4c615382f246 7090654: nightly failures after 7086585
never
parents: 10546
diff changeset
    61
  write_u2(java_fields);
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    62
  for (JavaFieldStream fs(ikh()); !fs.done(); fs.next()) {
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    63
    AccessFlags access_flags = fs.access_flags();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    64
    int name_index = fs.name_index();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    65
    int signature_index = fs.signature_index();
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    66
    int initial_value_index = fs.initval_index();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    guarantee(name_index != 0 && signature_index != 0, "bad constant pool index for field");
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    68
    // int offset = ikh()->field_offset( index );
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    69
    int generic_signature_index = fs.generic_signature_index();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
    70
    AnnotationArray* anno = fields_anno == NULL ? NULL : fields_anno->at(fs.index());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    // JVMSpec|   field_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    // JVMSpec|         u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    // JVMSpec|         u2 name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
    // JVMSpec|         u2 descriptor_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
    // JVMSpec|         u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    // JVMSpec|         attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    // JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
10546
e79347eebbc5 7086585: make Java field injection more flexible
never
parents: 8921
diff changeset
    80
    write_u2(access_flags.as_int() & JVM_RECOGNIZED_FIELD_MODIFIERS);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    write_u2(name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    write_u2(signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    if (initial_value_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      // ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
    93
    if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
    write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    if (initial_value_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
      write_attribute_name_index("ConstantValue");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      write_u4(2); //length always 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      write_u2(initial_value_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      // write_synthetic_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
    if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      write_signature_attribute(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   110
    if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
// Write Code attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// JVMSpec|   Code_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// JVMSpec|     u2 max_stack;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// JVMSpec|     u2 max_locals;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
// JVMSpec|     u4 code_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// JVMSpec|     u1 code[code_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// JVMSpec|     u2 exception_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// JVMSpec|     {       u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// JVMSpec|             u2 end_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// JVMSpec|             u2  handler_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
// JVMSpec|             u2  catch_type;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// JVMSpec|     }       exception_table[exception_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
void JvmtiClassFileReconstituter::write_code_attribute(methodHandle method) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   134
  ConstMethod* const_method = method->constMethod();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  u2 line_num_cnt = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  int stackmap_len = 0;
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   137
  int local_variable_table_length = 0;
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   138
  int local_variable_type_table_length = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   140
  // compute number and length of attributes
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  int attr_size = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  if (const_method->has_linenumber_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    line_num_cnt = line_number_table_entries(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    if (line_num_cnt != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // Compute the complete size of the line number table attribute:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      //      LineNumberTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
      //        u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      //        u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      //        u2 line_number_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      //        {  u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
      //           u2 line_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
      //        } line_number_table[line_number_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
      attr_size += 2 + 4 + 2 + line_num_cnt * (2 + 2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  if (method->has_stackmap_table()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    stackmap_len = method->stackmap_data()->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    if (stackmap_len != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
      // Compute the  size of the stack map table attribute (VM stores raw):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      //      StackMapTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
      //        u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
      //        u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      //        u2 number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      //        stack_map_frame_entries[number_of_entries];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      //      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      attr_size += 2 + 4 + stackmap_len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  }
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   173
  if (method->has_localvariable_table()) {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   174
    local_variable_table_length = method->localvariable_table_length();
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   175
    if (local_variable_table_length != 0) {
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   176
      ++attr_count;
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   177
      // Compute the size of the local variable table attribute (VM stores raw):
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   178
      // LocalVariableTable_attribute {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   179
      //   u2 attribute_name_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   180
      //   u4 attribute_length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   181
      //   u2 local_variable_table_length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   182
      //   {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   183
      //     u2 start_pc;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   184
      //     u2 length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   185
      //     u2 name_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   186
      //     u2 descriptor_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   187
      //     u2 index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   188
      //   }
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   189
      attr_size += 2 + 4 + 2 + local_variable_table_length * (2 + 2 + 2 + 2 + 2);
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   190
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   191
      // Local variables with generic signatures must have LVTT entries
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   192
      LocalVariableTableElement *elem = method->localvariable_table_start();
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   193
      for (int idx = 0; idx < local_variable_table_length; idx++) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   194
        if (elem[idx].signature_cp_index != 0) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   195
          local_variable_type_table_length++;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   196
        }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   197
      }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   198
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   199
      if (local_variable_type_table_length != 0) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   200
        ++attr_count;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   201
        // Compute the size of the local variable type table attribute (VM stores raw):
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   202
        // LocalVariableTypeTable_attribute {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   203
        //   u2 attribute_name_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   204
        //   u4 attribute_length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   205
        //   u2 local_variable_type_table_length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   206
        //   {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   207
        //     u2 start_pc;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   208
        //     u2 length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   209
        //     u2 name_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   210
        //     u2 signature_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   211
        //     u2 index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   212
        //   }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   213
        attr_size += 2 + 4 + 2 + local_variable_type_table_length * (2 + 2 + 2 + 2 + 2);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   214
      }
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   215
    }
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   216
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
13282
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   218
  ExceptionTable exception_table(method());
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   219
  int exception_table_length = exception_table.length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  int code_size = const_method->code_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  int size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    2+2+4 +                                // max_stack, max_locals, code_length
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    code_size +                            // code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    2 +                                    // exception_table_length
13282
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   225
    (2+2+2+2) * exception_table_length +   // exception_table
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    2 +                                    // attributes_count
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    attr_size;                             // attributes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  write_attribute_name_index("Code");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  write_u2(method->max_stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  write_u2(method->max_locals());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  write_u4(code_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  copy_bytecodes(method, (unsigned char*)writeable_address(code_size));
13282
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   235
  write_u2(exception_table_length);
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   236
  for (int index = 0; index < exception_table_length; index++) {
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   237
    write_u2(exception_table.start_pc(index));
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   238
    write_u2(exception_table.end_pc(index));
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   239
    write_u2(exception_table.handler_pc(index));
9872915dd78d 7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents: 12231
diff changeset
   240
    write_u2(exception_table.catch_type_index(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (line_num_cnt != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    write_line_number_table_attribute(method, line_num_cnt);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  if (stackmap_len != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
    write_stackmap_table_attribute(method, stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  }
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   249
  if (local_variable_table_length != 0) {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   250
    write_local_variable_table_attribute(method, local_variable_table_length);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   251
  }
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   252
  if (local_variable_type_table_length != 0) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   253
    write_local_variable_type_table_attribute(method, local_variable_type_table_length);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   254
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
// Write Exceptions attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
// JVMSpec|   Exceptions_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
// JVMSpec|     u2 number_of_exceptions;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
// JVMSpec|     u2 exception_index_table[number_of_exceptions];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// JVMSpec|   }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   264
void JvmtiClassFileReconstituter::write_exceptions_attribute(ConstMethod* const_method) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  CheckedExceptionElement* checked_exceptions = const_method->checked_exceptions_start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  int checked_exceptions_length = const_method->checked_exceptions_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  int size =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
    2 +                                    // number_of_exceptions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
    2 * checked_exceptions_length;         // exception_index_table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
  write_attribute_name_index("Exceptions");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
  write_u2(checked_exceptions_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
  for (int index = 0; index < checked_exceptions_length; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    write_u2(checked_exceptions[index].class_cp_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
// Write SourceFile attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
// JVMSpec|   SourceFile_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
// JVMSpec|     u2 sourcefile_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
void JvmtiClassFileReconstituter::write_source_file_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  assert(ikh()->source_file_name() != NULL, "caller must check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  write_attribute_name_index("SourceFile");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  write_u4(2);  // always length 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  write_u2(symbol_to_cpool_index(ikh()->source_file_name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
// Write SourceDebugExtension attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
// JSR45|   SourceDebugExtension_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
// JSR45|       u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
// JSR45|       u4 attribute_length;
13201
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   297
// JSR45|       u1 debug_extension[attribute_length];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
// JSR45|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
void JvmtiClassFileReconstituter::write_source_debug_extension_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  assert(ikh()->source_debug_extension() != NULL, "caller must check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  write_attribute_name_index("SourceDebugExtension");
13201
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   303
  int len = (int)strlen(ikh()->source_debug_extension());
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   304
  write_u4(len);
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   305
  u1* ext = (u1*)ikh()->source_debug_extension();
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   306
  for (int i=0; i<len; i++) {
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   307
    write_u1(ext[i]);
69f157caabcc 6294277: java -Xdebug crashes on SourceDebugExtension attribute larger than 64K
fparain
parents: 12231
diff changeset
   308
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
// Write (generic) Signature attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
// JVMSpec|   Signature_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
// JVMSpec|     u2 signature_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
void JvmtiClassFileReconstituter::write_signature_attribute(u2 generic_signature_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  write_attribute_name_index("Signature");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  write_u4(2);  // always length 2
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  write_u2(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
// Compute the number of entries in the InnerClasses attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
u2 JvmtiClassFileReconstituter::inner_classes_attribute_length() {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   325
  InnerClassesIterator iter(ikh());
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   326
  return iter.length();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
// Write an annotation attribute.  The VM stores them in raw form, so all we need
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
// to do is add the attrubute name and fill in the length.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
// JSR202|   *Annotations_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
// JSR202|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
// JSR202|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
// JSR202|     ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
// JSR202|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
void JvmtiClassFileReconstituter::write_annotations_attribute(const char* attr_name,
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   337
                                                              AnnotationArray* annos) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  u4 length = annos->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  write_attribute_name_index(attr_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  write_u4(length);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   341
  memcpy(writeable_address(length), annos->adr_at(0), length);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// Write InnerClasses attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
// JVMSpec|   InnerClasses_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
// JVMSpec|     u2 number_of_classes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
// JVMSpec|     {  u2 inner_class_info_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
// JVMSpec|        u2 outer_class_info_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
// JVMSpec|        u2 inner_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
// JVMSpec|        u2 inner_class_access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
// JVMSpec|     } classes[number_of_classes];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
void JvmtiClassFileReconstituter::write_inner_classes_attribute(int length) {
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   357
  InnerClassesIterator iter(ikh());
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   358
  guarantee(iter.length() != 0 && iter.length() == length,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
            "caller must check");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   360
  u2 entry_count = length / InstanceKlass::inner_class_next_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  u4 size = 2 + entry_count * (2+2+2+2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  write_attribute_name_index("InnerClasses");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
  write_u4(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  write_u2(entry_count);
12231
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   366
  for (; !iter.done(); iter.next()) {
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   367
    write_u2(iter.inner_class_info_index());
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   368
    write_u2(iter.outer_class_info_index());
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   369
    write_u2(iter.inner_name_index());
6a9cfc59a18a 7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents: 12102
diff changeset
   370
    write_u2(iter.inner_access_flags());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// Write Synthetic attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// JVMSpec|   Synthetic_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
void JvmtiClassFileReconstituter::write_synthetic_attribute() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  write_attribute_name_index("Synthetic");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  write_u4(0); //length always zero
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
// Compute size of LineNumberTable
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
u2 JvmtiClassFileReconstituter::line_number_table_entries(methodHandle method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  // The line number table is compressed so we don't know how big it is until decompressed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  // Decompression is really fast so we just do it twice.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  u2 num_entries = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  while (stream.read_pair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
    num_entries++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  return num_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
// Write LineNumberTable attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
// JVMSpec|   LineNumberTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
// JVMSpec|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
// JVMSpec|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
// JVMSpec|     u2 line_number_table_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
// JVMSpec|     {  u2 start_pc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
// JVMSpec|        u2 line_number;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
// JVMSpec|     } line_number_table[line_number_table_length];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
void JvmtiClassFileReconstituter::write_line_number_table_attribute(methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
                                                                    u2 num_entries) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  write_attribute_name_index("LineNumberTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  write_u4(2 + num_entries * (2 + 2));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  write_u2(num_entries);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  CompressedLineNumberReadStream stream(method->compressed_linenumber_table());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  while (stream.read_pair()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
    write_u2(stream.bci());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
    write_u2(stream.line());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   419
// Write LocalVariableTable attribute
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   420
// JVMSpec|   LocalVariableTable_attribute {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   421
// JVMSpec|     u2 attribute_name_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   422
// JVMSpec|     u4 attribute_length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   423
// JVMSpec|     u2 local_variable_table_length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   424
// JVMSpec|     {  u2 start_pc;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   425
// JVMSpec|       u2 length;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   426
// JVMSpec|       u2 name_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   427
// JVMSpec|       u2 descriptor_index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   428
// JVMSpec|       u2 index;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   429
// JVMSpec|     } local_variable_table[local_variable_table_length];
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   430
// JVMSpec|   }
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   431
void JvmtiClassFileReconstituter::write_local_variable_table_attribute(methodHandle method, u2 num_entries) {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   432
    write_attribute_name_index("LocalVariableTable");
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   433
    write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2));
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   434
    write_u2(num_entries);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   435
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   436
    assert(method->localvariable_table_length() == num_entries, "just checking");
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   437
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   438
    LocalVariableTableElement *elem = method->localvariable_table_start();
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   439
    for (int j=0; j<method->localvariable_table_length(); j++) {
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   440
      write_u2(elem->start_bci);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   441
      write_u2(elem->length);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   442
      write_u2(elem->name_cp_index);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   443
      write_u2(elem->descriptor_cp_index);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   444
      write_u2(elem->slot);
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   445
      elem++;
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   446
    }
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   447
}
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 10552
diff changeset
   448
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   449
// Write LocalVariableTypeTable attribute
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   450
// JVMSpec|   LocalVariableTypeTable_attribute {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   451
// JVMSpec|     u2 attribute_name_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   452
// JVMSpec|     u4 attribute_length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   453
// JVMSpec|     u2 local_variable_type_table_length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   454
// JVMSpec|     { u2 start_pc;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   455
// JVMSpec|       u2 length;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   456
// JVMSpec|       u2 name_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   457
// JVMSpec|       u2 signature_index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   458
// JVMSpec|       u2 index;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   459
// JVMSpec|     } local_variable_type_table[local_variable_type_table_length];
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   460
// JVMSpec|   }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   461
void JvmtiClassFileReconstituter::write_local_variable_type_table_attribute(methodHandle method, u2 num_entries) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   462
    write_attribute_name_index("LocalVariableTypeTable");
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   463
    write_u4(2 + num_entries * (2 + 2 + 2 + 2 + 2));
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   464
    write_u2(num_entries);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   465
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   466
    LocalVariableTableElement *elem = method->localvariable_table_start();
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   467
    for (int j=0; j<method->localvariable_table_length(); j++) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   468
      if (elem->signature_cp_index > 0) {
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   469
        // Local variable has a generic signature - write LVTT attribute entry
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   470
        write_u2(elem->start_bci);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   471
        write_u2(elem->length);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   472
        write_u2(elem->name_cp_index);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   473
        write_u2(elem->signature_cp_index);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   474
        write_u2(elem->slot);
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   475
        num_entries--;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   476
      }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   477
      elem++;
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   478
    }
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   479
    assert(num_entries == 0, "just checking");
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   480
}
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   481
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
// Write stack map table attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
// JSR-202|   StackMapTable_attribute {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
// JSR-202|     u2 attribute_name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
// JSR-202|     u4 attribute_length;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
// JSR-202|     u2 number_of_entries;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
// JSR-202|     stack_map_frame_entries[number_of_entries];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
// JSR-202|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
void JvmtiClassFileReconstituter::write_stackmap_table_attribute(methodHandle method,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
                                                                 int stackmap_len) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  write_attribute_name_index("StackMapTable");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  write_u4(stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
  memcpy(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
    writeable_address(stackmap_len),
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   496
    (void*)(method->stackmap_data()->adr_at(0)),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
    stackmap_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
// Write one method_info structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
// JVMSpec|   method_info {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
// JVMSpec|     u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
// JVMSpec|     u2 name_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
// JVMSpec|     u2 descriptor_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
// JVMSpec|   }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
void JvmtiClassFileReconstituter::write_method_info(methodHandle method) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  AccessFlags access_flags = method->access_flags();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   510
  ConstMethod* const_method = method->constMethod();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
  u2 generic_signature_index = const_method->generic_signature_index();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   512
  AnnotationArray* anno = method->annotations();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   513
  AnnotationArray* param_anno = method->parameter_annotations();
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   514
  AnnotationArray* default_anno = method->annotation_default();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  write_u2(access_flags.get_flags() & JVM_RECOGNIZED_METHOD_MODIFIERS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  write_u2(const_method->name_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  write_u2(const_method->signature_index());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // write attributes in the same order javac does, so we can test with byte for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // byte comparison
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  int attr_count = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  if (const_method->code_size() != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    ++attr_count;     // has Code attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  if (const_method->has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
    ++attr_count;     // has Exceptions attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   529
  if (default_anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    ++attr_count;     // has AnnotationDefault attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  // Deprecated attribute would go here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  if (access_flags.is_synthetic()) { // FIXME
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    // ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
  if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   539
  if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   542
  if (param_anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
    ++attr_count;     // has RuntimeVisibleParameterAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  if (const_method->code_size() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
    write_code_attribute(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  if (const_method->has_checked_exceptions()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
    write_exceptions_attribute(const_method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   553
  if (default_anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    write_annotations_attribute("AnnotationDefault", default_anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  // Deprecated attribute would go here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
  if (access_flags.is_synthetic()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
    // write_synthetic_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  if (generic_signature_index != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    write_signature_attribute(generic_signature_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   563
  if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   566
  if (param_anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
    write_annotations_attribute("RuntimeVisibleParameterAnnotations", param_anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
// Write the class attributes portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
// JVMSpec|     u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
// JVMSpec|     attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
void JvmtiClassFileReconstituter::write_class_attributes() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
  u2 inner_classes_length = inner_classes_attribute_length();
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   576
  Symbol* generic_signature = ikh()->generic_signature();
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   577
  AnnotationArray* anno = ikh()->class_annotations();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  int attr_count = 0;
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   580
  if (generic_signature != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  if (ikh()->source_file_name() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  if (ikh()->source_debug_extension() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  if (inner_classes_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
    ++attr_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   592
  if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
    ++attr_count;     // has RuntimeVisibleAnnotations attribute
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
  write_u2(attr_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   598
  if (generic_signature != NULL) {
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   599
    write_signature_attribute(symbol_to_cpool_index(generic_signature));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
  if (ikh()->source_file_name() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
    write_source_file_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
  if (ikh()->source_debug_extension() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
    write_source_debug_extension_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
  if (inner_classes_length > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    write_inner_classes_attribute(inner_classes_length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
  }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   610
  if (anno != NULL) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
    write_annotations_attribute("RuntimeVisibleAnnotations", anno);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
// Write the method information portion of ClassFile structure
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
// JVMSpec|     u2 methods_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
// JVMSpec|     method_info methods[methods_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
void JvmtiClassFileReconstituter::write_method_infos() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
  HandleMark hm(thread());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   620
  Array<Method*>* methods = ikh()->methods();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  int num_methods = methods->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  write_u2(num_methods);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
  if (JvmtiExport::can_maintain_original_method_order()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
    int index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
    int original_index;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   627
    intArray method_order(num_methods, 0);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
    // invert the method order mapping
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
    for (index = 0; index < num_methods; index++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   631
      original_index = ikh()->method_ordering()->at(index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
      assert(original_index >= 0 && original_index < num_methods,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
             "invalid original method index");
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   634
      method_order.at_put(original_index, index);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    // write in original order
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
    for (original_index = 0; original_index < num_methods; original_index++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   639
      index = method_order.at(original_index);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   640
      methodHandle method(thread(), methods->at(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
      write_method_info(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
    // method order not preserved just dump the method infos
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
    for (int index = 0; index < num_methods; index++) {
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   646
      methodHandle method(thread(), methods->at(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
      write_method_info(method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
void JvmtiClassFileReconstituter::write_class_file_format() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
  ReallocMark();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  // JVMSpec|   ClassFile {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
  // JVMSpec|           u4 magic;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
  write_u4(0xCAFEBABE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  // JVMSpec|           u2 minor_version;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  // JVMSpec|           u2 major_version;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  write_u2(ikh()->minor_version());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  u2 major = ikh()->major_version();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  write_u2(major);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // JVMSpec|           u2 constant_pool_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  // JVMSpec|           cp_info constant_pool[constant_pool_count-1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  write_u2(cpool()->length());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  copy_cpool_bytes(writeable_address(cpool_size()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  // JVMSpec|           u2 access_flags;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  write_u2(ikh()->access_flags().get_flags() & JVM_RECOGNIZED_CLASS_MODIFIERS);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  // JVMSpec|           u2 this_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
  // JVMSpec|           u2 super_class;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  write_u2(class_symbol_to_cpool_index(ikh()->name()));
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   676
  Klass* super_class = ikh()->super();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
  write_u2(super_class == NULL? 0 :  // zero for java.lang.Object
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   678
                class_symbol_to_cpool_index(super_class->name()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
  // JVMSpec|           u2 interfaces_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
  // JVMSpec|           u2 interfaces[interfaces_count];
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   682
  Array<Klass*>* interfaces =  ikh()->local_interfaces();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
  int num_interfaces = interfaces->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
  write_u2(num_interfaces);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  for (int index = 0; index < num_interfaces; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
    HandleMark hm(thread());
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   687
    instanceKlassHandle iikh(thread(), interfaces->at(index));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
    write_u2(class_symbol_to_cpool_index(iikh->name()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
  // JVMSpec|           u2 fields_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
  // JVMSpec|           field_info fields[fields_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
  write_field_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  // JVMSpec|           u2 methods_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  // JVMSpec|           method_info methods[methods_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  write_method_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
  // JVMSpec|           u2 attributes_count;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
  // JVMSpec|           attribute_info attributes[attributes_count];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
  // JVMSpec|   } /* end ClassFile 8?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
  write_class_attributes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
address JvmtiClassFileReconstituter::writeable_address(size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
  size_t used_size = _buffer_ptr - _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
  if (size + used_size >= _buffer_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
    // compute the new buffer size: must be at least twice as big as before
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
    // plus whatever new is being used; then convert to nice clean block boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
    size_t new_buffer_size = (size + _buffer_size*2 + 1) / initial_buffer_size
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
                                                         * initial_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
    // VM goes belly-up if the memory isn't available, so cannot do OOM processing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
    _buffer = REALLOC_RESOURCE_ARRAY(u1, _buffer, _buffer_size, new_buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
    _buffer_size = new_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
    _buffer_ptr = _buffer + used_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
  u1* ret_ptr = _buffer_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
  _buffer_ptr += size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
  return ret_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
void JvmtiClassFileReconstituter::write_attribute_name_index(const char* name) {
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
   724
  TempNewSymbol sym = SymbolTable::probe(name, (int)strlen(name));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  assert(sym != NULL, "attribute name symbol not found");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
  u2 attr_name_index = symbol_to_cpool_index(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
  assert(attr_name_index != 0, "attribute name symbol not in constant pool");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
  write_u2(attr_name_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
void JvmtiClassFileReconstituter::write_u1(u1 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  *writeable_address(1) = x;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
void JvmtiClassFileReconstituter::write_u2(u2 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
  Bytes::put_Java_u2(writeable_address(2), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
void JvmtiClassFileReconstituter::write_u4(u4 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  Bytes::put_Java_u4(writeable_address(4), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
void JvmtiClassFileReconstituter::write_u8(u8 x) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  Bytes::put_Java_u8(writeable_address(8), x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
void JvmtiClassFileReconstituter::copy_bytecodes(methodHandle mh,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
                                                 unsigned char* bytecodes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
  // use a BytecodeStream to iterate over the bytecodes. JVM/fast bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  // and the breakpoint bytecode are converted to their original bytecodes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  BytecodeStream bs(mh);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  unsigned char* p = bytecodes;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  Bytecodes::Code code;
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   756
  bool is_rewritten = InstanceKlass::cast(mh->method_holder())->is_rewritten();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
  while ((code = bs.next()) >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
    assert(Bytecodes::is_java_code(code), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
    assert(code != Bytecodes::_breakpoint, "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
    // length of bytecode (mnemonic + operands)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
    address bcp = bs.bcp();
5688
9052dc91ea67 6939207: refactor constant pool index processing
jrose
parents: 3261
diff changeset
   764
    int     len = bs.instruction_size();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
    assert(len > 0, "length must be > 0");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    // copy the bytecodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
    *p = (unsigned char) (bs.is_wide()? Bytecodes::_wide : code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    if (len > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
      memcpy(p+1, bcp+1, len-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
    // During linking the get/put and invoke instructions are rewritten
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
    // with an index into the constant pool cache. The original constant
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
    // pool index must be returned to caller.  Rewrite the index.
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   776
    if (is_rewritten && len > 1) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   777
      bool is_wide = false;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
      switch (code) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      case Bytecodes::_getstatic       :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
      case Bytecodes::_putstatic       :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
      case Bytecodes::_getfield        :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      case Bytecodes::_putfield        :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
      case Bytecodes::_invokevirtual   :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
      case Bytecodes::_invokespecial   :  // fall through
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
      case Bytecodes::_invokestatic    :  // fall through
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   786
      case Bytecodes::_invokedynamic   :  // fall through
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   787
      case Bytecodes::_invokeinterface : {
12102
7a1c6c80bc23 7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents: 11257
diff changeset
   788
        assert(len == 3 ||
7a1c6c80bc23 7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents: 11257
diff changeset
   789
               (code == Bytecodes::_invokeinterface && len == 5) ||
7a1c6c80bc23 7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents: 11257
diff changeset
   790
               (code == Bytecodes::_invokedynamic   && len == 5),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
               "sanity check");
12102
7a1c6c80bc23 7118280: The gbyc00102 JCK7 test causes an assert in JVM 7.0 fastdebug mode
dsamersoff
parents: 11257
diff changeset
   792
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   793
        int cpci = Bytes::get_native_u2(bcp+1);
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   794
        bool is_invokedynamic = (EnableInvokeDynamic && code == Bytecodes::_invokedynamic);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   795
        ConstantPoolCacheEntry* entry;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   796
        if (is_invokedynamic) {
2570
ecc7862946d4 6655646: dynamic languages need dynamically linked call sites
jrose
parents: 1
diff changeset
   797
          cpci = Bytes::get_native_u4(bcp+1);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   798
          entry = mh->constants()->invokedynamic_cp_cache_entry_at(cpci);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   799
        } else {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   800
        // cache cannot be pre-fetched since some classes won't have it yet
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   801
          entry = mh->constants()->cache()->entry_at(cpci);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   802
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   803
        int i = entry->constant_pool_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   804
        assert(i < mh->constants()->length(), "sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   805
        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
   806
        if (is_invokedynamic)  *(p+3) = *(p+4) = 0;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   807
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   808
      }
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   809
      case Bytecodes::_ldc_w:
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   810
        is_wide = true; // fall through
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   811
      case Bytecodes::_ldc: {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   812
        if (bs.raw_code() == Bytecodes::_fast_aldc || bs.raw_code() == Bytecodes::_fast_aldc_w) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   813
          int cpci = is_wide ? Bytes::get_native_u2(bcp+1) : (u1)(*(bcp+1));
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   814
          int i = mh->constants()->object_to_cp_index(cpci);
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   815
          assert(i < mh->constants()->length(), "sanity check");
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   816
          if (is_wide) {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   817
            Bytes::put_Java_u2((address)(p+1), (u2)i);     // java byte ordering
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   818
          } else {
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   819
            *(p+1) = (u1)i;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   820
          }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   821
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   822
        break;
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   823
        }
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13286
diff changeset
   824
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
    p += len;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
}