hotspot/src/share/vm/prims/jvmtiClassFileReconstituter.hpp
author sla
Mon, 06 May 2013 19:49:18 +0200
changeset 17307 74bb7db916df
parent 13863 3a6dfc8fdfd1
child 17309 83ac929d332a
permissions -rw-r--r--
8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes Reviewed-by: coleenp, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
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: 5547
diff changeset
    25
#ifndef SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "jvmtifiles/jvmtiEnv.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
class JvmtiConstantPoolReconstituter : public StackObj {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  int                  _cpool_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  SymbolHashMap*       _symmap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  SymbolHashMap*       _classmap;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  constantPoolHandle   _cpool;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  instanceKlassHandle  _ikh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  jvmtiError           _err;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  instanceKlassHandle  ikh()     { return _ikh; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  constantPoolHandle   cpool()   { return _cpool; };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    44
  u2 symbol_to_cpool_index(Symbol* sym) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    return _symmap->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
8076
96d498ec7ae1 6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents: 7397
diff changeset
    48
  u2 class_symbol_to_cpool_index(Symbol* sym) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    return _classmap->symbol_to_value(sym);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  // Calls to this constructor must be proceeded by a ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // and a HandleMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  JvmtiConstantPoolReconstituter(instanceKlassHandle ikh){
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
    set_error(JVMTI_ERROR_NONE);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
    _ikh = ikh;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    _cpool = constantPoolHandle(Thread::current(), ikh->constants());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
    _symmap = new SymbolHashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    _classmap = new SymbolHashMap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    _cpool_size = _cpool->hash_entries_to(_symmap, _classmap);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    if (_cpool_size == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      set_error(JVMTI_ERROR_OUT_OF_MEMORY);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    } else if (_cpool_size < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      set_error(JVMTI_ERROR_INTERNAL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  ~JvmtiConstantPoolReconstituter() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    if (_symmap != NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11257
diff changeset
    71
      os::free(_symmap, mtClass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      _symmap = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (_classmap != NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11257
diff changeset
    75
      os::free(_classmap, mtClass);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
      _classmap = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  void       set_error(jvmtiError err)    { _err = err; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  jvmtiError get_error()                  { return _err; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  int cpool_size()                        { return _cpool_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  void copy_cpool_bytes(unsigned char *cpool_bytes) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    if (cpool_bytes == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
      assert(cpool_bytes != NULL, "cpool_bytes pointer must not be NULL");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    cpool()->copy_cpool_bytes(cpool_size(), _symmap, cpool_bytes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
class JvmtiClassFileReconstituter : public JvmtiConstantPoolReconstituter {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  size_t               _buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  u1*                  _buffer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  u1*                  _buffer_ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  Thread*              _thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    // initial size should be power of two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
    initial_buffer_size = 1024
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  inline Thread* thread() { return _thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  void write_class_file_format();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  void write_field_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  void write_method_infos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  void write_method_info(methodHandle method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  void write_code_attribute(methodHandle method);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   115
  void write_exceptions_attribute(ConstMethod* const_method);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  void write_synthetic_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  void write_class_attributes();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  void write_source_file_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  void write_source_debug_extension_attribute();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  u2 line_number_table_entries(methodHandle method);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  void write_line_number_table_attribute(methodHandle method, u2 num_entries);
11257
b98dfa12a8f7 7064927: retransformClasses() does not pass in LocalVariableTable of a method
coleenp
parents: 8921
diff changeset
   122
  void write_local_variable_table_attribute(methodHandle method, u2 num_entries);
13863
3a6dfc8fdfd1 7191786: retransformClasses() does not pass in LocalVariableTypeTable of a method
minqi
parents: 13728
diff changeset
   123
  void write_local_variable_type_table_attribute(methodHandle method, u2 num_entries);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  void write_stackmap_table_attribute(methodHandle method, int stackmap_table_len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  u2 inner_classes_attribute_length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  void write_inner_classes_attribute(int length);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void write_signature_attribute(u2 generic_signaure_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  void write_attribute_name_index(const char* name);
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
   129
  void write_annotations_attribute(const char* attr_name, AnnotationArray* annos);
17307
74bb7db916df 8009615: JvmtiClassFileReconstituter does not create BootstrapMethod attributes
sla
parents: 13863
diff changeset
   130
  void write_boostrapmethod_attribute();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  address writeable_address(size_t size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  void write_u1(u1 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  void write_u2(u2 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  void write_u4(u4 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  void write_u8(u8 x);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  // Calls to this constructor must be proceeded by a ResourceMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  // and a HandleMark
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  JvmtiClassFileReconstituter(instanceKlassHandle ikh) :
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
                                      JvmtiConstantPoolReconstituter(ikh) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    _buffer_size = initial_buffer_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    _buffer = _buffer_ptr = NEW_RESOURCE_ARRAY(u1, _buffer_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    _thread = Thread::current();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    write_class_file_format();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  size_t class_file_size()    { return _buffer_ptr - _buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  u1* class_file_bytes()      { return _buffer; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  static void copy_bytecodes(methodHandle method, unsigned char* bytecodes);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   155
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   156
#endif // SHARE_VM_PRIMS_JVMTICLASSFILERECONSTITUTER_HPP