src/hotspot/share/jfr/instrumentation/jfrEventClassTransformer.cpp
author mgronlun
Mon, 28 Oct 2019 18:43:04 +0100
branchJEP-349-branch
changeset 58823 6a21dba79b81
parent 58157 9dca61a7df19
child 58837 2bfbb50dd97d
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     1
/*
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     4
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     8
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    13
 * accompanied this code).
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    14
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    18
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    21
 * questions.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    22
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    23
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    24
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    25
#include "precompiled.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    26
#include "jvm.h"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    27
#include "classfile/classFileParser.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    28
#include "classfile/classFileStream.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    29
#include "classfile/javaClasses.inline.hpp"
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    30
#include "classfile/moduleEntry.hpp"
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    31
#include "classfile/modules.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    32
#include "classfile/stackMapTable.hpp"
54786
ebf733a324d4 8223624: Cleanup includes of universe.hpp
stefank
parents: 53838
diff changeset
    33
#include "classfile/symbolTable.hpp"
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    34
#include "classfile/verificationType.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    35
#include "interpreter/bytecodes.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    36
#include "jfr/instrumentation/jfrEventClassTransformer.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    37
#include "jfr/jfr.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    38
#include "jfr/jni/jfrJavaSupport.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    39
#include "jfr/jni/jfrUpcalls.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    40
#include "jfr/support/jfrEventClass.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    41
#include "jfr/utilities/jfrBigEndian.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    42
#include "jfr/writers/jfrBigEndianWriter.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    43
#include "logging/log.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    44
#include "memory/allocation.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    45
#include "memory/resourceArea.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    46
#include "oops/array.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    47
#include "oops/instanceKlass.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    48
#include "oops/method.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    49
#include "prims/jvmtiRedefineClasses.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    50
#include "runtime/handles.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    51
#include "runtime/os.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    52
#include "runtime/thread.inline.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    53
#include "utilities/exceptions.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    54
#include "utilities/globalDefinitions.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    55
#include "utilities/macros.hpp"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    56
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    57
static const u2 number_of_new_methods = 5;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    58
static const u2 number_of_new_fields = 3;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    59
static const int extra_stream_bytes = 0x280;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    60
static const u2 invalid_cp_index = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    61
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    62
static const char* utf8_constants[] = {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    63
  "Code",         // 0
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    64
  "J",            // 1
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    65
  "commit",       // 2
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    66
  "eventHandler", // 3
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    67
  "duration",     // 4
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    68
  "begin",        // 5
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    69
  "()V",          // 6
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    70
  "isEnabled",    // 7
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    71
  "()Z",          // 8
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    72
  "end",          // 9
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    73
  "shouldCommit", // 10
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    74
  "startTime",    // 11 // LAST_REQUIRED_UTF8
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    75
  "Ljdk/jfr/internal/handlers/EventHandler;", // 12
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    76
  "Ljava/lang/Object;", // 13
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    77
  "<clinit>",     // 14
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    78
  "jdk/jfr/FlightRecorder", // 15
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    79
  "register",     // 16
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    80
  "(Ljava/lang/Class;)V", // 17
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    81
  "StackMapTable", // 18
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    82
  "Exceptions", // 19
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    83
  "LineNumberTable", // 20
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    84
  "LocalVariableTable", // 21
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    85
  "LocalVariableTypeTable", // 22
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
    86
  "RuntimeVisibleAnnotation", // 23
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    87
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    88
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    89
enum utf8_req_symbols {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    90
  UTF8_REQ_Code,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    91
  UTF8_REQ_J_FIELD_DESC,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    92
  UTF8_REQ_commit,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    93
  UTF8_REQ_eventHandler,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    94
  UTF8_REQ_duration,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    95
  UTF8_REQ_begin,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    96
  UTF8_REQ_EMPTY_VOID_METHOD_DESC,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    97
  UTF8_REQ_isEnabled,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    98
  UTF8_REQ_EMPTY_BOOLEAN_METHOD_DESC,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
    99
  UTF8_REQ_end,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   100
  UTF8_REQ_shouldCommit,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   101
  UTF8_REQ_startTime,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   102
  NOF_UTF8_REQ_SYMBOLS
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   103
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   104
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   105
enum utf8_opt_symbols {
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   106
  UTF8_OPT_eventHandler_FIELD_DESC = NOF_UTF8_REQ_SYMBOLS,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   107
  UTF8_OPT_LjavaLangObject,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   108
  UTF8_OPT_clinit,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   109
  UTF8_OPT_FlightRecorder,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   110
  UTF8_OPT_register,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   111
  UTF8_OPT_CLASS_VOID_METHOD_DESC,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   112
  UTF8_OPT_StackMapTable,
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   113
  UTF8_OPT_Exceptions,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   114
  UTF8_OPT_LineNumberTable,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   115
  UTF8_OPT_LocalVariableTable,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   116
  UTF8_OPT_LocalVariableTypeTable,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   117
  UTF8_OPT_RuntimeVisibleAnnotation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   118
  NOF_UTF8_SYMBOLS
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   119
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   120
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   121
static u1 empty_void_method_code_attribute[] = {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   122
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   123
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   124
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   125
  0xd, // attribute len
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   126
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   127
  0x0, // max stack
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   128
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   129
  0x1, // max locals
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   130
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   131
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   132
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   133
  0x1, // code length
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   134
  Bytecodes::_return,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   135
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   136
  0x0, // ex table len
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   137
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   138
  0x0  // attributes_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   139
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   140
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   141
static u1 boolean_method_code_attribute[] = {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   142
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   143
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   144
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   145
  0xe,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   146
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   147
  0x1, // max stack
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   148
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   149
  0x1, // max locals
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   150
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   151
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   152
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   153
  0x2,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   154
  Bytecodes::_iconst_0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   155
  Bytecodes::_ireturn,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   156
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   157
  0x0, // ex table len
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   158
  0x0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   159
  0x0, // attributes_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   160
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   161
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   162
// annotation processing support
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   163
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   164
enum {  // initial annotation layout
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   165
  atype_off = 0,      // utf8 such as 'Ljava/lang/annotation/Retention;'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   166
  count_off = 2,      // u2   such as 1 (one value)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   167
  member_off = 4,     // utf8 such as 'value'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   168
  tag_off = 6,        // u1   such as 'c' (type) or 'e' (enum)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   169
  e_tag_val = 'e',
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   170
  e_type_off = 7,   // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   171
  e_con_off = 9,    // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   172
  e_size = 11,     // end of 'e' annotation
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   173
  c_tag_val = 'c',    // payload is type
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   174
  c_con_off = 7,    // utf8 payload, such as 'I'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   175
  c_size = 9,       // end of 'c' annotation
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   176
  s_tag_val = 's',    // payload is String
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   177
  s_con_off = 7,    // utf8 payload, such as 'Ljava/lang/String;'
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   178
  s_size = 9,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   179
  min_size = 6        // smallest possible size (zero members)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   180
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   181
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   182
static int skip_annotation_value(const address, int, int); // fwd decl
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   183
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   184
// Skip an annotation.  Return >=limit if there is any problem.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   185
static int next_annotation_index(const address buffer, int limit, int index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   186
  assert(buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   187
  index += 2;  // skip atype
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   188
  if ((index += 2) >= limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   189
    return limit;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   190
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   191
  int nof_members = JfrBigEndian::read<u2>(buffer + index - 2);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   192
  while (--nof_members >= 0 && index < limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   193
    index += 2; // skip member
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   194
    index = skip_annotation_value(buffer, limit, index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   195
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   196
  return index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   197
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   198
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   199
// Skip an annotation value.  Return >=limit if there is any problem.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   200
static int skip_annotation_value(const address buffer, int limit, int index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   201
  assert(buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   202
  // value := switch (tag:u1) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   203
  //   case B, C, I, S, Z, D, F, J, c: con:u2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   204
  //   case e: e_class:u2 e_name:u2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   205
  //   case s: s_con:u2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   206
  //   case [: do(nval:u2) {value};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   207
  //   case @: annotation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   208
  //   case s: s_con:u2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   209
  // }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   210
  if ((index += 1) >= limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   211
    return limit;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   212
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   213
  const u1 tag = buffer[index - 1];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   214
  switch (tag) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   215
    case 'B':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   216
    case 'C':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   217
    case 'I':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   218
    case 'S':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   219
    case 'Z':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   220
    case 'D':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   221
    case 'F':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   222
    case 'J':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   223
    case 'c':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   224
    case 's':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   225
      index += 2;  // skip con or s_con
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   226
      break;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   227
    case 'e':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   228
      index += 4;  // skip e_class, e_name
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   229
      break;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   230
    case '[':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   231
      {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   232
        if ((index += 2) >= limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   233
          return limit;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   234
        }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   235
        int nof_values = JfrBigEndian::read<u2>(buffer + index - 2);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   236
        while (--nof_values >= 0 && index < limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   237
          index = skip_annotation_value(buffer, limit, index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   238
        }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   239
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   240
      break;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   241
    case '@':
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   242
      index = next_annotation_index(buffer, limit, index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   243
      break;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   244
    default:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   245
      return limit;  //  bad tag byte
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   246
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   247
  return index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   248
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   249
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   250
static const u2 number_of_elements_offset = (u2)2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   251
static const u2 element_name_offset = (u2)(number_of_elements_offset + 2);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   252
static const u2 element_name_size = (u2)2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   253
static const u2 value_type_relative_offset = (u2)2;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   254
static const u2 value_relative_offset = (u2)(value_type_relative_offset + 1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   255
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   256
// see JVMS - 4.7.16. The RuntimeVisibleAnnotations Attribute
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   257
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   258
class AnnotationElementIterator : public StackObj {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   259
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   260
  const InstanceKlass* _ik;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   261
  const address _buffer;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   262
  const u2 _limit; // length of annotation
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   263
  mutable u2 _current; // element
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   264
  mutable u2 _next; // element
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   265
  u2 value_index() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   266
    return JfrBigEndian::read<u2>(_buffer + _current + value_relative_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   267
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   268
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   269
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   270
  AnnotationElementIterator(const InstanceKlass* ik, address buffer, u2 limit) : _ik(ik),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   271
                                                                                 _buffer(buffer),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   272
                                                                                 _limit(limit),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50123
diff changeset
   273
                                                                                 _current(element_name_offset),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50123
diff changeset
   274
                                                                                 _next(element_name_offset) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   275
    assert(_buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   276
    assert(_next == element_name_offset, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   277
    assert(_current == element_name_offset, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   278
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   279
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   280
  bool has_next() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   281
    return _next < _limit;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   282
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   283
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   284
  void move_to_next() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   285
    assert(has_next(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   286
    _current = _next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   287
    if (_next < _limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   288
      _next = skip_annotation_value(_buffer, _limit, _next + element_name_size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   289
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   290
    assert(_next <= _limit, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   291
    assert(_current <= _limit, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   292
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   293
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   294
  u2 number_of_elements() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   295
    return JfrBigEndian::read<u2>(_buffer + number_of_elements_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   296
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   297
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   298
  const Symbol* name() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   299
    assert(_current < _next, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   300
    return _ik->constants()->symbol_at(JfrBigEndian::read<u2>(_buffer + _current));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   301
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   302
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   303
  char value_type() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   304
    return JfrBigEndian::read<u1>(_buffer + _current + value_type_relative_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   305
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   306
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   307
  jint read_int() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   308
    return _ik->constants()->int_at(value_index());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   309
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   310
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   311
  bool read_bool() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   312
    return read_int() != 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   313
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   314
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   315
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   316
class AnnotationIterator : public StackObj {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   317
 private:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   318
  const InstanceKlass* _ik;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   319
  // ensure _limit field is declared before _buffer
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   320
  u2 _limit; // length of annotations array
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   321
  const address _buffer;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   322
  mutable u2 _current; // annotation
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   323
  mutable u2 _next; // annotation
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   324
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   325
 public:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   326
  AnnotationIterator(const InstanceKlass* ik, AnnotationArray* ar) : _ik(ik),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50123
diff changeset
   327
                                                                     _limit(ar != NULL ? ar->length() : 0),
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50123
diff changeset
   328
                                                                     _buffer(_limit > 2 ? ar->adr_at(2) : NULL),
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   329
                                                                     _current(0),
51334
cc2c79d22508 8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents: 50123
diff changeset
   330
                                                                     _next(0) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   331
    if (_buffer != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   332
      _limit -= 2; // subtract sizeof(u2) number of annotations field
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   333
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   334
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   335
  bool has_next() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   336
    return _next < _limit;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   337
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   338
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   339
  void move_to_next() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   340
    assert(has_next(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   341
    _current = _next;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   342
    if (_next < _limit) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   343
      _next = next_annotation_index(_buffer, _limit, _next);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   344
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   345
    assert(_next <= _limit, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   346
    assert(_current <= _limit, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   347
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   348
  const AnnotationElementIterator elements() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   349
    assert(_current < _next, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   350
    return AnnotationElementIterator(_ik, _buffer + _current, _next - _current);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   351
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   352
  const Symbol* type() const {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   353
    assert(_buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   354
    assert(_current < _limit, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   355
    return _ik->constants()->symbol_at(JfrBigEndian::read<u2>(_buffer + _current));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   356
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   357
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   358
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   359
static const char value_name[] = "value";
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   360
static bool has_annotation(const InstanceKlass* ik, const Symbol* annotation_type, bool& value) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   361
  assert(annotation_type != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   362
  AnnotationArray* class_annotations = ik->class_annotations();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   363
  if (class_annotations == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   364
    return false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   365
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   366
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   367
  const AnnotationIterator annotation_iterator(ik, class_annotations);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   368
  while (annotation_iterator.has_next()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   369
    annotation_iterator.move_to_next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   370
    if (annotation_iterator.type() == annotation_type) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   371
      // target annotation found
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   372
      static const Symbol* value_symbol =
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   373
        SymbolTable::probe(value_name, sizeof value_name - 1);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   374
      assert(value_symbol != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   375
      const AnnotationElementIterator element_iterator = annotation_iterator.elements();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   376
      while (element_iterator.has_next()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   377
        element_iterator.move_to_next();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   378
        if (value_symbol == element_iterator.name()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   379
          // "value" element
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   380
          assert('Z' == element_iterator.value_type(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   381
          value = element_iterator.read_bool();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   382
          return true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   383
        }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   384
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   385
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   386
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   387
  return false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   388
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   389
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   390
// Evaluate to the value of the first found Symbol* annotation type.
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   391
// Searching moves upwards in the klass hierarchy in order to support
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   392
// inherited annotations in addition to the ability to override.
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   393
static bool annotation_value(const InstanceKlass* ik, const Symbol* annotation_type, bool& value) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   394
  assert(ik != NULL, "invariant");
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   395
  assert(annotation_type != NULL, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   396
  assert(JdkJfrEvent::is_a(ik), "invariant");
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   397
  if (has_annotation(ik, annotation_type, value)) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   398
    return true;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   399
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   400
  InstanceKlass* const super = InstanceKlass::cast(ik->super());
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   401
  return super != NULL && JdkJfrEvent::is_a(super) ? annotation_value(super, annotation_type, value) : false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   402
}
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   403
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   404
static const char jdk_jfr_module_name[] = "jdk.jfr";
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   405
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   406
static bool java_base_can_read_jdk_jfr() {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   407
  static bool can_read = false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   408
  if (can_read) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   409
    return true;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   410
  }
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   411
  static Symbol* jdk_jfr_module_symbol = NULL;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   412
  if (jdk_jfr_module_symbol == NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   413
    jdk_jfr_module_symbol = SymbolTable::probe(jdk_jfr_module_name, sizeof jdk_jfr_module_name - 1);
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   414
    if (jdk_jfr_module_symbol == NULL) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   415
      return false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   416
    }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   417
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   418
  assert(jdk_jfr_module_symbol != NULL, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   419
  ModuleEntryTable* const table = Modules::get_module_entry_table(Handle());
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   420
  assert(table != NULL, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   421
  const ModuleEntry* const java_base_module = table->javabase_moduleEntry();
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   422
  if (java_base_module == NULL) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   423
    return false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   424
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   425
  assert(java_base_module != NULL, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   426
  ModuleEntry* const jdk_jfr_module = table->lookup_only(jdk_jfr_module_symbol);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   427
  if (jdk_jfr_module == NULL) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   428
    return false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   429
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   430
  assert(jdk_jfr_module != NULL, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   431
  if (java_base_module->can_read(jdk_jfr_module)) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   432
    can_read = true;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   433
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   434
  return can_read;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   435
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   436
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   437
static const char registered_constant[] = "Ljdk/jfr/Registered;";
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   438
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   439
// Evaluate to the value of the first found "Ljdk/jfr/Registered;" annotation.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   440
// Searching moves upwards in the klass hierarchy in order to support
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   441
// inherited annotations in addition to the ability to override.
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   442
static bool should_register_klass(const InstanceKlass* ik, bool& untypedEventHandler) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   443
  assert(ik != NULL, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   444
  assert(JdkJfrEvent::is_a(ik), "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   445
  assert(!untypedEventHandler, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   446
  static const Symbol* registered_symbol = NULL;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   447
  if (registered_symbol == NULL) {
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
   448
    registered_symbol = SymbolTable::probe(registered_constant, sizeof registered_constant - 1);
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   449
    if (registered_symbol == NULL) {
52671
600fca45232b 8214161: java.lang.IllegalAccessError: class jdk.internal.event.X509CertificateEvent (in module java.base) cannot access class jdk.jfr.internal.handlers.EventHandler (in module jdk.jfr) because module java.base does not read module jdk.jfr
mgronlun
parents: 52334
diff changeset
   450
      untypedEventHandler = true;
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   451
      return false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   452
    }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   453
  }
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   454
  assert(registered_symbol != NULL, "invariant");
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   455
  bool value = false; // to be set by annotation_value
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   456
  untypedEventHandler = !(annotation_value(ik, registered_symbol, value) || java_base_can_read_jdk_jfr());
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   457
  return value;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   458
}
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   459
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   460
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   461
 * Map an utf8 constant back to its CONSTANT_UTF8_INFO
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   462
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   463
static u2 utf8_info_index(const InstanceKlass* ik, const Symbol* const target, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   464
  assert(target != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   465
  const ConstantPool* cp = ik->constants();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   466
  const int cp_len = cp->length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   467
  for (u2 index = 1; index < cp_len; ++index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   468
    const constantTag tag = cp->tag_at(index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   469
    if (tag.is_utf8()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   470
      const Symbol* const utf8_sym = cp->symbol_at(index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   471
      assert(utf8_sym != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   472
      if (utf8_sym == target) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   473
        return index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   474
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   475
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   476
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   477
  // not in constant pool
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   478
  return invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   479
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   480
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   481
#ifdef ASSERT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   482
static bool is_index_within_range(u2 index, u2 orig_cp_len, u2 new_cp_entries_len) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   483
  return index > 0 && index < orig_cp_len + new_cp_entries_len;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   484
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   485
#endif
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   486
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   487
static u2 add_utf8_info(JfrBigEndianWriter& writer, const char* utf8_constant, u2 orig_cp_len, u2& new_cp_entries_len) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   488
  assert(utf8_constant != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   489
  writer.write<u1>(JVM_CONSTANT_Utf8);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   490
  writer.write_utf8_u2_len(utf8_constant);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   491
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   492
  // return index for the added utf8 info
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   493
  return orig_cp_len + new_cp_entries_len++;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   494
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   495
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   496
static u2 add_method_ref_info(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   497
                              u2 cls_name_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   498
                              u2 method_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   499
                              u2 desc_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   500
                              u2 orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   501
                              u2& number_of_new_constants,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   502
                              TRAPS) {
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   503
  assert(cls_name_index != invalid_cp_index, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   504
  assert(method_index != invalid_cp_index, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   505
  assert(desc_index != invalid_cp_index, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   506
  assert(is_index_within_range(cls_name_index, orig_cp_len, number_of_new_constants), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   507
  assert(is_index_within_range(method_index, orig_cp_len, number_of_new_constants), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   508
  assert(is_index_within_range(desc_index, orig_cp_len, number_of_new_constants), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   509
  writer.write<u1>(JVM_CONSTANT_Class);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   510
  writer.write<u2>(cls_name_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   511
  const u2 cls_entry_index = orig_cp_len + number_of_new_constants;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   512
  ++number_of_new_constants;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   513
  writer.write<u1>(JVM_CONSTANT_NameAndType);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   514
  writer.write<u2>(method_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   515
  writer.write<u2>(desc_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   516
  const u2 nat_entry_index = orig_cp_len + number_of_new_constants;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   517
  ++number_of_new_constants;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   518
  writer.write<u1>(JVM_CONSTANT_Methodref);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   519
  writer.write<u2>(cls_entry_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   520
  writer.write<u2>(nat_entry_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   521
  // post-increment number_of_new_constants
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   522
  // value returned is the index to the added method_ref
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   523
  return orig_cp_len + number_of_new_constants++;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   524
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   525
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   526
static u2 add_flr_register_method_constants(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   527
                                            const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   528
                                            u2 orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   529
                                            u2& number_of_new_constants,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   530
                                            TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   531
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   532
  return add_method_ref_info(writer,
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   533
                             utf8_indexes[UTF8_OPT_FlightRecorder],
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   534
                             utf8_indexes[UTF8_OPT_register],
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   535
                             utf8_indexes[UTF8_OPT_CLASS_VOID_METHOD_DESC],
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   536
                             orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   537
                             number_of_new_constants,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   538
                             THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   539
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   540
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   541
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   542
 * field_info {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   543
 *   u2             access_flags;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   544
 *   u2             name_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   545
 *   u2             descriptor_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   546
 *   u2             attributes_count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   547
 *   attribute_info attributes[attributes_count];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   548
 * }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   549
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   550
static jlong add_field_info(JfrBigEndianWriter& writer, u2 name_index, u2 desc_index, bool is_static = false) {
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   551
  assert(name_index != invalid_cp_index, "invariant");
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   552
  assert(desc_index != invalid_cp_index, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   553
  DEBUG_ONLY(const jlong start_offset = writer.current_offset();)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   554
  writer.write<u2>(JVM_ACC_SYNTHETIC | JVM_ACC_PRIVATE | (is_static ? JVM_ACC_STATIC : JVM_ACC_TRANSIENT)); // flags
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   555
  writer.write(name_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   556
  writer.write(desc_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   557
  writer.write((u2)0x0); // attributes_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   558
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   559
  DEBUG_ONLY(assert(start_offset + 8 == writer.current_offset(), "invariant");)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   560
  return writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   561
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   562
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   563
static u2 add_field_infos(JfrBigEndianWriter& writer, const u2* utf8_indexes, bool untypedEventHandler) {
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   564
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   565
  add_field_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   566
                 utf8_indexes[UTF8_REQ_eventHandler],
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
   567
                 untypedEventHandler ? utf8_indexes[UTF8_OPT_LjavaLangObject] : utf8_indexes[UTF8_OPT_eventHandler_FIELD_DESC],
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   568
                 true); // static
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   569
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   570
  add_field_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   571
                 utf8_indexes[UTF8_REQ_startTime],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   572
                 utf8_indexes[UTF8_REQ_J_FIELD_DESC]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   573
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   574
  add_field_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   575
                 utf8_indexes[UTF8_REQ_duration],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   576
                 utf8_indexes[UTF8_REQ_J_FIELD_DESC]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   577
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   578
  return number_of_new_fields;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   579
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   580
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   581
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   582
 * method_info {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   583
 *  u2             access_flags;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   584
 *  u2             name_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   585
 *  u2             descriptor_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   586
 *  u2             attributes_count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   587
 *  attribute_info attributes[attributes_count];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   588
 * }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   589
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   590
 * Code_attribute {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   591
 *   u2 attribute_name_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   592
 *   u4 attribute_length;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   593
 *   u2 max_stack;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   594
 *   u2 max_locals;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   595
 *   u4 code_length;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   596
 *   u1 code[code_length];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   597
 *   u2 exception_table_length;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   598
 *   {   u2 start_pc;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   599
 *       u2 end_pc;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   600
 *       u2 handler_pc;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   601
 *       u2 catch_type;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   602
 *   } exception_table[exception_table_length];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   603
 *   u2 attributes_count;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   604
 *   attribute_info attributes[attributes_count];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   605
 * }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   606
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   607
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   608
static jlong add_method_info(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   609
                             u2 name_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   610
                             u2 desc_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   611
                             u2 code_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   612
                             const u1* const code,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   613
                             const size_t code_len) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   614
  assert(name_index > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   615
  assert(desc_index > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   616
  assert(code_index > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   617
  DEBUG_ONLY(const jlong start_offset = writer.current_offset();)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   618
  writer.write<u2>(JVM_ACC_SYNTHETIC | JVM_ACC_PUBLIC); // flags
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   619
  writer.write(name_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   620
  writer.write(desc_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   621
  writer.write<u2>(0x1); // attributes_count ; 1 for "Code" attribute
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   622
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   623
  DEBUG_ONLY(assert(start_offset + 8 == writer.current_offset(), "invariant");)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   624
  // Code attribute
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   625
  writer.write(code_index); // "Code"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   626
  writer.bytes(code, code_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   627
  DEBUG_ONLY(assert((start_offset + 8 + 2 + (jlong)code_len) == writer.current_offset(), "invariant");)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   628
  return writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   629
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   630
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   631
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   632
 * On return, the passed stream will be positioned
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   633
 * just after the constant pool section in the classfile
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   634
 * and the cp length is returned.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   635
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   636
 * Stream should come in at the start position.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   637
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   638
static u2 position_stream_after_cp(const ClassFileStream* stream) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   639
  assert(stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   640
  assert(stream->current_offset() == 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   641
  stream->skip_u4_fast(2);  // 8 bytes skipped
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   642
  const u2 cp_len = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   643
  assert(cp_len > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   644
  // now spin the stream position to just after the constant pool
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   645
  for (u2 index = 1; index < cp_len; ++index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   646
    const u1 tag = stream->get_u1_fast(); // cp tag
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   647
    switch (tag) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   648
      case JVM_CONSTANT_Class:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   649
      case JVM_CONSTANT_String: {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   650
        stream->skip_u2_fast(1); // skip 2 bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   651
        continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   652
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   653
      case JVM_CONSTANT_Fieldref:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   654
      case JVM_CONSTANT_Methodref:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   655
      case JVM_CONSTANT_InterfaceMethodref:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   656
      case JVM_CONSTANT_Integer:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   657
      case JVM_CONSTANT_Float:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   658
      case JVM_CONSTANT_NameAndType:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   659
      case JVM_CONSTANT_InvokeDynamic: {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   660
        stream->skip_u4_fast(1); // skip 4 bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   661
        continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   662
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   663
      case JVM_CONSTANT_Long:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   664
      case JVM_CONSTANT_Double: {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   665
        stream->skip_u4_fast(2); // skip 8 bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   666
        // Skip entry following eigth-byte constant, see JVM book p. 98
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   667
        ++index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   668
        continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   669
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   670
      case JVM_CONSTANT_Utf8: {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   671
        u2 utf8_length = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   672
        stream->skip_u1_fast(utf8_length); // skip 2 + len bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   673
        continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   674
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   675
      case JVM_CONSTANT_MethodHandle:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   676
      case JVM_CONSTANT_MethodType: {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   677
        if (tag == JVM_CONSTANT_MethodHandle) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   678
          stream->skip_u1_fast(1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   679
          stream->skip_u2_fast(1); // skip 3 bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   680
        }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   681
        else if (tag == JVM_CONSTANT_MethodType) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   682
          stream->skip_u2_fast(1); // skip 3 bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   683
        }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   684
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   685
      continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   686
      default:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   687
        assert(false, "error in skip logic!");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   688
        break;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   689
    } // end switch(tag)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   690
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   691
  return cp_len;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   692
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   693
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   694
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   695
* On return, the passed stream will be positioned
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   696
* just after the fields section in the classfile
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   697
* and the number of fields will be returned.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   698
*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   699
* Stream should come in positioned just before fields_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   700
*/
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   701
static u2 position_stream_after_fields(const ClassFileStream* stream) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   702
  assert(stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   703
  assert(stream->current_offset() > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   704
  // fields len
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   705
  const u2 orig_fields_len = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   706
  // fields
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   707
  for (u2 i = 0; i < orig_fields_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   708
    stream->skip_u2_fast(3);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   709
    const u2 attrib_info_len = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   710
    for (u2 j = 0; j < attrib_info_len; ++j) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   711
      stream->skip_u2_fast(1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   712
      const u4 attrib_len = stream->get_u4_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   713
      stream->skip_u1_fast(attrib_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   714
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   715
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   716
  return orig_fields_len;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   717
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   718
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   719
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   720
* On return, the passed stream will be positioned
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   721
* just after the methods section in the classfile
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   722
* and the number of methods will be returned.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   723
*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   724
* Stream should come in positioned just before methods_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   725
*/
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   726
static u2 position_stream_after_methods(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   727
                                        const ClassFileStream* stream,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   728
                                        const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   729
                                        bool register_klass,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   730
                                        const Method* clinit_method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   731
                                        u4& orig_method_len_offset) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   732
  assert(stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   733
  assert(stream->current_offset() > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   734
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   735
  // We will come back to this location when we
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   736
  // know how many methods there will be.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   737
  writer.reserve(sizeof(u2));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   738
  const u2 orig_methods_len = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   739
  // Move copy position past original method_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   740
  // in order to not copy the original count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   741
  orig_method_len_offset += sizeof(u2);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   742
  for (u2 i = 0; i < orig_methods_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   743
    const u4 method_offset = stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   744
    stream->skip_u2_fast(1); // Access Flags
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   745
    const u2 name_index = stream->get_u2_fast(); // Name index
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   746
    stream->skip_u2_fast(1); // Descriptor index
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   747
    const u2 attributes_count = stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   748
    for (u2 j = 0; j < attributes_count; ++j) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   749
      stream->skip_u2_fast(1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   750
      const u4 attrib_len = stream->get_u4_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   751
      stream->skip_u1_fast(attrib_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   752
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   753
    if (clinit_method != NULL && name_index == clinit_method->name_index()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   754
      // The method just parsed is an existing <clinit> method.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   755
      // If the class has the @Registered(false) annotation, i.e. marking a class
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   756
      // for opting out from automatic registration, then we do not need to do anything.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   757
      if (!register_klass) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   758
        continue;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   759
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   760
      // Automatic registration with the jfr system is acccomplished
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   761
      // by pre-pending code to the <clinit> method of the class.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   762
      // We will need to re-create a new <clinit> in a later step.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   763
      // For now, ensure that this method is excluded from the methods
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   764
      // being copied.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   765
      writer.bytes(stream->buffer() + orig_method_len_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   766
                   method_offset - orig_method_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   767
      assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   768
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   769
      // Update copy position to skip copy of <clinit> method
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   770
      orig_method_len_offset = stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   771
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   772
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   773
  return orig_methods_len;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   774
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   775
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   776
static u2 add_method_infos(JfrBigEndianWriter& writer, const u2* utf8_indexes) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   777
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   778
  add_method_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   779
                  utf8_indexes[UTF8_REQ_begin],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   780
                  utf8_indexes[UTF8_REQ_EMPTY_VOID_METHOD_DESC],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   781
                  utf8_indexes[UTF8_REQ_Code],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   782
                  empty_void_method_code_attribute,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   783
                  sizeof(empty_void_method_code_attribute));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   784
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   785
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   786
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   787
  add_method_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   788
                  utf8_indexes[UTF8_REQ_end],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   789
                  utf8_indexes[UTF8_REQ_EMPTY_VOID_METHOD_DESC],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   790
                  utf8_indexes[UTF8_REQ_Code],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   791
                  empty_void_method_code_attribute,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   792
                  sizeof(empty_void_method_code_attribute));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   793
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   794
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   795
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   796
  add_method_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   797
                  utf8_indexes[UTF8_REQ_commit],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   798
                  utf8_indexes[UTF8_REQ_EMPTY_VOID_METHOD_DESC],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   799
                  utf8_indexes[UTF8_REQ_Code],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   800
                  empty_void_method_code_attribute,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   801
                  sizeof(empty_void_method_code_attribute));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   802
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   803
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   804
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   805
  add_method_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   806
                  utf8_indexes[UTF8_REQ_isEnabled],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   807
                  utf8_indexes[UTF8_REQ_EMPTY_BOOLEAN_METHOD_DESC],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   808
                  utf8_indexes[UTF8_REQ_Code],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   809
                  boolean_method_code_attribute,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   810
                  sizeof(boolean_method_code_attribute));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   811
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   812
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   813
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   814
  add_method_info(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   815
                  utf8_indexes[UTF8_REQ_shouldCommit],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   816
                  utf8_indexes[UTF8_REQ_EMPTY_BOOLEAN_METHOD_DESC],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   817
                  utf8_indexes[UTF8_REQ_Code],
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   818
                  boolean_method_code_attribute,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   819
                  sizeof(boolean_method_code_attribute));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   820
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   821
  return number_of_new_methods;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   822
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   823
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   824
static void adjust_exception_table(JfrBigEndianWriter& writer, u2 bci_adjustment_offset, const Method* method, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   825
  const u2 ex_table_length = method != NULL ? (u2)method->exception_table_length() : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   826
  writer.write<u2>(ex_table_length); // Exception table length
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   827
  if (ex_table_length > 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   828
    assert(method != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   829
    const ExceptionTableElement* const ex_elements = method->exception_table_start();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   830
    for (int i = 0; i < ex_table_length; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   831
      assert(ex_elements != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   832
      writer.write<u2>(ex_elements[i].start_pc + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   833
      writer.write<u2>(ex_elements[i].end_pc + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   834
      writer.write<u2>(ex_elements[i].handler_pc + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   835
      writer.write<u2>(ex_elements[i].catch_type_index); // no adjustment
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   836
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   837
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   838
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   839
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   840
enum StackMapFrameTypes {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   841
  SAME_FRAME_BEGIN = 0,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   842
  SAME_FRAME_END = 63,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   843
  SAME_LOCALS_1_STACK_ITEM_FRAME_BEGIN = 64,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   844
  SAME_LOCALS_1_STACK_ITEM_FRAME_END = 127,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   845
  SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED = 247,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   846
  CHOP_FRAME_BEGIN = 248,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   847
  CHOP_FRAME_END = 250,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   848
  SAME_FRAME_EXTENDED = 251,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   849
  APPEND_FRAME_BEGIN = 252,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   850
  APPEND_FRAME_END = 254,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   851
  FULL_FRAME = 255
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   852
};
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   853
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   854
static void adjust_stack_map(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   855
                             Array<u1>* stack_map,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   856
                             const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   857
                             u2 bci_adjustment_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   858
                             TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   859
  assert(stack_map != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   860
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   861
  writer.write<u2>(utf8_indexes[UTF8_OPT_StackMapTable]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   862
  const jlong stack_map_attrib_len_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   863
  writer.reserve(sizeof(u4));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   864
  StackMapStream stream(stack_map);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   865
  const u2 stack_map_entries = stream.get_u2(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   866
  // number of entries
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   867
  writer.write<u2>(stack_map_entries); // new stack map entry added
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   868
  const u1 frame_type = stream.get_u1(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   869
  // SAME_FRAME and SAME_LOCALS_1_STACK_ITEM_FRAME encode
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   870
  // their offset_delta into the actual frame type itself.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   871
  // If such a frame type is the first frame, then we transform
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   872
  // it to a SAME_FRAME_EXTENDED or a SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED frame.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   873
  // This is done in order to not overflow frame types accidentally
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   874
  // when adjusting the offset_delta. In changing the frame types,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   875
  // we can work with an explicit u2 offset_delta field (like the other frame types)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   876
  if (frame_type <= SAME_FRAME_END) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   877
    writer.write<u1>(SAME_FRAME_EXTENDED);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   878
    writer.write<u2>(frame_type + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   879
  } else if (frame_type >= SAME_LOCALS_1_STACK_ITEM_FRAME_BEGIN &&
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   880
             frame_type <= SAME_LOCALS_1_STACK_ITEM_FRAME_END) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   881
    writer.write<u1>(SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   882
    writer.write<u2>((frame_type - SAME_LOCALS_1_STACK_ITEM_FRAME_BEGIN) + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   883
  } else if (frame_type >= SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   884
      // SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED to FULL_FRAME
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   885
      // has a u2 offset_delta field
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   886
      writer.write<u1>(frame_type);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   887
      writer.write<u2>(stream.get_u2(THREAD) + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   888
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   889
    assert(false, "stackMapFrame type is invalid");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   890
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   891
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   892
  while (!stream.at_end()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   893
    writer.write<u1>(stream.get_u1(THREAD));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   894
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   895
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   896
  u4 stack_map_attrib_len = writer.current_offset() - stack_map_attrib_len_offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   897
  // the stack_map_table_attributes_length value is exclusive
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   898
  stack_map_attrib_len -= sizeof(u4);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   899
  writer.write_at_offset(stack_map_attrib_len, stack_map_attrib_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   900
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   901
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   902
static void adjust_line_number_table(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   903
                                     const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   904
                                     u4 bci_adjustement_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   905
                                     const Method* method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   906
                                     TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   907
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   908
  assert(method != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   909
  assert(method->has_linenumber_table(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   910
  writer.write(utf8_indexes[UTF8_OPT_LineNumberTable]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   911
  const jlong lnt_attributes_length_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   912
  writer.reserve(sizeof(u4));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   913
  const jlong lnt_attributes_entries_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   914
  writer.reserve(sizeof(u2));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   915
  u1* lnt = method->compressed_linenumber_table();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   916
  CompressedLineNumberReadStream lnt_stream(lnt);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   917
  u2 line_number_table_entries = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   918
  while (lnt_stream.read_pair()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   919
    ++line_number_table_entries;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   920
    const u2 bci = (u2)lnt_stream.bci();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   921
    writer.write<u2>(bci + (u2)bci_adjustement_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   922
    writer.write<u2>((u2)lnt_stream.line());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   923
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   924
  writer.write_at_offset(line_number_table_entries, lnt_attributes_entries_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   925
  u4 lnt_table_attributes_len = writer.current_offset() - lnt_attributes_length_offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   926
  // the line_number_table_attributes_length value is exclusive
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   927
  lnt_table_attributes_len -= sizeof(u4);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   928
  writer.write_at_offset(lnt_table_attributes_len, lnt_attributes_length_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   929
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   930
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   931
// returns the number of lvtt entries
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   932
static u2 adjust_local_variable_table(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   933
                                      const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   934
                                      u2 bci_adjustment_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   935
                                      const Method* method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   936
                                      TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   937
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   938
  assert(method != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   939
  assert(method->has_localvariable_table(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   940
  writer.write<u2>(utf8_indexes[UTF8_OPT_LocalVariableTable]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   941
  const jlong lvt_attributes_length_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   942
  writer.reserve(sizeof(u4));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   943
  const int lvt_len = method->localvariable_table_length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   944
  writer.write<u2>((u2)lvt_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   945
  const LocalVariableTableElement* table = method->localvariable_table_start();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   946
  assert(table != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   947
  u2 num_lvtt_entries = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   948
  for (int i = 0; i < lvt_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   949
    writer.write<u2>(table[i].start_bci + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   950
    writer.write<u2>(table[i].length);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   951
    writer.write<u2>(table[i].name_cp_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   952
    writer.write<u2>(table[i].descriptor_cp_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   953
    writer.write<u2>(table[i].slot);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   954
    if (table[i].signature_cp_index > 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   955
      ++num_lvtt_entries;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   956
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   957
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   958
  u4 lvt_table_attributes_len = writer.current_offset() - lvt_attributes_length_offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   959
  // the lvt_table_attributes_length value is exclusive
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   960
  lvt_table_attributes_len -= sizeof(u4);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   961
  writer.write_at_offset(lvt_table_attributes_len, lvt_attributes_length_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   962
  return num_lvtt_entries;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   963
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   964
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   965
static void adjust_local_variable_type_table(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   966
                                            const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   967
                                            u2 bci_adjustment_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   968
                                            u2 num_lvtt_entries,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   969
                                            const Method* method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   970
                                            TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   971
  assert(num_lvtt_entries > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   972
  writer.write<u2>(utf8_indexes[UTF8_OPT_LocalVariableTypeTable]);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   973
  const jlong lvtt_attributes_length_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   974
  writer.reserve(sizeof(u4));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   975
  writer.write<u2>(num_lvtt_entries);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   976
  const LocalVariableTableElement* table = method->localvariable_table_start();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   977
  assert(table != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   978
  const int lvt_len = method->localvariable_table_length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   979
  for (int i = 0; i < lvt_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   980
    if (table[i].signature_cp_index > 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   981
      writer.write<u2>(table[i].start_bci + bci_adjustment_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   982
      writer.write<u2>(table[i].length);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   983
      writer.write<u2>(table[i].name_cp_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   984
      writer.write<u2>(table[i].signature_cp_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   985
      writer.write<u2>(table[i].slot);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   986
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   987
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   988
  u4 lvtt_table_attributes_len = writer.current_offset() - lvtt_attributes_length_offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   989
  // the lvtt_table_attributes_length value is exclusive
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   990
  lvtt_table_attributes_len -= sizeof(u4);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   991
  writer.write_at_offset(lvtt_table_attributes_len, lvtt_attributes_length_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   992
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   993
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   994
static void adjust_code_attributes(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   995
                                   const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   996
                                   u2 bci_adjustment_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   997
                                   const Method* clinit_method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   998
                                   TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
   999
  // "Code" attributes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1000
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1001
  const jlong code_attributes_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1002
  writer.reserve(sizeof(u2));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1003
  u2 number_of_code_attributes = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1004
  if (clinit_method != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1005
    Array<u1>* stack_map = clinit_method->stackmap_data();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1006
    if (stack_map != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1007
      ++number_of_code_attributes;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1008
      adjust_stack_map(writer, stack_map, utf8_indexes, bci_adjustment_offset, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1009
      assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1010
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1011
    if (clinit_method != NULL && clinit_method->has_linenumber_table()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1012
      ++number_of_code_attributes;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1013
      adjust_line_number_table(writer, utf8_indexes, bci_adjustment_offset, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1014
      assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1015
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1016
    if (clinit_method != NULL && clinit_method->has_localvariable_table()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1017
      ++number_of_code_attributes;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1018
      const u2 num_of_lvtt_entries = adjust_local_variable_table(writer, utf8_indexes, bci_adjustment_offset, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1019
      assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1020
      if (num_of_lvtt_entries > 0) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1021
        ++number_of_code_attributes;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1022
        adjust_local_variable_type_table(writer, utf8_indexes, bci_adjustment_offset, num_of_lvtt_entries, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1023
        assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1024
      }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1025
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1026
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1027
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1028
  // Store the number of code_attributes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1029
  writer.write_at_offset(number_of_code_attributes, code_attributes_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1030
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1031
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1032
static jlong insert_clinit_method(const InstanceKlass* ik,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1033
                                  const ClassFileParser& parser,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1034
                                  JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1035
                                  u2 orig_constant_pool_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1036
                                  const u2* utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1037
                                  const u2 register_method_ref_index,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1038
                                  const Method* clinit_method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1039
                                  TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1040
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1041
  // The injected code length is always this value.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1042
  // This is to ensure that padding can be done
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1043
  // where needed and to simplify size calculations.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1044
  static const u2 injected_code_length = 8;
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1045
  const u2 name_index = utf8_indexes[UTF8_OPT_clinit];
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1046
  assert(name_index != invalid_cp_index, "invariant");
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1047
  const u2 desc_index = utf8_indexes[UTF8_REQ_EMPTY_VOID_METHOD_DESC];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1048
  const u2 max_stack = MAX2(clinit_method != NULL ? clinit_method->verifier_max_stack() : 1, 1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1049
  const u2 max_locals = MAX2(clinit_method != NULL ? clinit_method->max_locals() : 0, 0);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1050
  const u2 orig_bytecodes_length = clinit_method != NULL ? (u2)clinit_method->code_size() : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1051
  const address orig_bytecodes = clinit_method != NULL ? clinit_method->code_base() : NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1052
  const u2 new_code_length = injected_code_length + orig_bytecodes_length;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1053
  DEBUG_ONLY(const jlong start_offset = writer.current_offset();)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1054
  writer.write<u2>(JVM_ACC_STATIC); // flags
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1055
  writer.write<u2>(name_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1056
  writer.write<u2>(desc_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1057
  writer.write<u2>((u2)0x1); // attributes_count // "Code"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1058
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1059
  DEBUG_ONLY(assert(start_offset + 8 == writer.current_offset(), "invariant");)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1060
  // "Code" attribute
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1061
  writer.write<u2>(utf8_indexes[UTF8_REQ_Code]); // "Code"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1062
  const jlong code_attribute_length_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1063
  writer.reserve(sizeof(u4));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1064
  writer.write<u2>(max_stack); // max stack
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1065
  writer.write<u2>(max_locals); // max locals
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1066
  writer.write<u4>((u4)new_code_length); // code length
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1067
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1068
  /* BEGIN CLINIT CODE */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1069
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1070
  // Note the use of ldc_w here instead of ldc.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1071
  // This is to handle all values of "this_class_index"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1072
  writer.write<u1>((u1)Bytecodes::_ldc_w);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1073
  writer.write<u2>((u2)parser.this_class_index()); // load constant "this class"
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1074
  writer.write<u1>((u1)Bytecodes::_invokestatic);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1075
  // invoke "FlightRecorder.register(Ljava/lang/Class;")
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1076
  writer.write<u2>(register_method_ref_index);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1077
  if (clinit_method == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1078
    writer.write<u1>((u1)Bytecodes::_nop);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1079
    writer.write<u1>((u1)Bytecodes::_return);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1080
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1081
    // If we are pre-pending to original code,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1082
    // do padding to minimize disruption to the original.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1083
    // It might have dependencies on 4-byte boundaries
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1084
    // i.e. lookupswitch and tableswitch instructions
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1085
    writer.write<u1>((u1)Bytecodes::_nop);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1086
    writer.write<u1>((u1)Bytecodes::_nop);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1087
    // insert original clinit code
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1088
    writer.bytes(orig_bytecodes, orig_bytecodes_length);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1089
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1090
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1091
  /* END CLINIT CODE */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1092
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1093
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1094
  adjust_exception_table(writer, injected_code_length, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1095
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1096
  adjust_code_attributes(writer, utf8_indexes, injected_code_length, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1097
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1098
  u4 code_attribute_len = writer.current_offset() - code_attribute_length_offset;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1099
  // the code_attribute_length value is exclusive
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1100
  code_attribute_len -= sizeof(u4);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1101
  writer.write_at_offset(code_attribute_len, code_attribute_length_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1102
  return writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1103
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1104
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1105
// Caller needs ResourceMark
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1106
static ClassFileStream* create_new_bytes_for_event_klass(const InstanceKlass* ik, const ClassFileParser& parser, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1107
  DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1108
  static const u2 public_final_flag_mask = JVM_ACC_PUBLIC | JVM_ACC_FINAL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1109
  const ClassFileStream* const orig_stream = parser.clone_stream();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1110
  const int orig_stream_length = orig_stream->length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1111
  // allocate an identically sized buffer
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1112
  u1* const new_buffer = NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(THREAD, u1, orig_stream_length);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1113
  if (new_buffer == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1114
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1115
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1116
  assert(new_buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1117
  // memcpy the entire [B
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1118
  memcpy(new_buffer, orig_stream->buffer(), orig_stream_length);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1119
  const u2 orig_cp_len = position_stream_after_cp(orig_stream);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1120
  assert(orig_cp_len > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1121
  assert(orig_stream->current_offset() > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1122
  orig_stream->skip_u2_fast(3); // access_flags, this_class_index, super_class_index
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1123
  const u2 iface_len = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1124
  orig_stream->skip_u2_fast(iface_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1125
  // fields len
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1126
  const u2 orig_fields_len = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1127
  // fields
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1128
  for (u2 i = 0; i < orig_fields_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1129
    orig_stream->skip_u2_fast(3);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1130
    const u2 attrib_info_len = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1131
    for (u2 j = 0; j < attrib_info_len; ++j) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1132
      orig_stream->skip_u2_fast(1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1133
      const u4 attrib_len = orig_stream->get_u4_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1134
      orig_stream->skip_u1_fast(attrib_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1135
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1136
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1137
  // methods
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1138
  const u2 orig_methods_len = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1139
  for (u2 i = 0; i < orig_methods_len; ++i) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1140
    const u4 access_flag_offset = orig_stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1141
    const u2 flags = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1142
    // Rewrite JVM_ACC_FINAL -> JVM_ACC_PUBLIC
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1143
    if (public_final_flag_mask == flags) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1144
      JfrBigEndianWriter accessflagsrewriter(new_buffer + access_flag_offset, sizeof(u2));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1145
      accessflagsrewriter.write<u2>(JVM_ACC_PUBLIC);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1146
      assert(accessflagsrewriter.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1147
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1148
    orig_stream->skip_u2_fast(2);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1149
    const u2 attributes_count = orig_stream->get_u2_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1150
    for (u2 j = 0; j < attributes_count; ++j) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1151
      orig_stream->skip_u2_fast(1);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1152
      const u4 attrib_len = orig_stream->get_u4_fast();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1153
      orig_stream->skip_u1_fast(attrib_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1154
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1155
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1156
  return new ClassFileStream(new_buffer, orig_stream_length, NULL, ClassFileStream::verify);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1157
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1158
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1159
// Attempt to locate an existing UTF8_INFO mapping the utf8_constant.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1160
// If no UTF8_INFO exists, add (append) a new one to the constant pool.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1161
static u2 find_or_add_utf8_info(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1162
                                const InstanceKlass* ik,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1163
                                const char* const utf8_constant,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1164
                                u2 orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1165
                                u2& added_cp_entries,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1166
                                TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1167
  assert(utf8_constant != NULL, "invariant");
54847
59ea39bb2809 8223657: Remove unused THREAD argument from SymbolTable functions
coleenp
parents: 54786
diff changeset
  1168
  TempNewSymbol utf8_sym = SymbolTable::new_symbol(utf8_constant);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1169
  // lookup existing
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1170
  const int utf8_orig_idx = utf8_info_index(ik, utf8_sym, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1171
  if (utf8_orig_idx != invalid_cp_index) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1172
    // existing constant pool entry found
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1173
    return utf8_orig_idx;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1174
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1175
  // no existing match, need to add a new utf8 cp entry
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1176
  assert(invalid_cp_index == utf8_orig_idx, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1177
  // add / append new
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1178
  return add_utf8_info(writer, utf8_constant, orig_cp_len, added_cp_entries);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1179
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1180
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1181
/*
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1182
 * This routine will resolve the required utf8_constants array
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1183
 * to their constant pool indexes (mapping to their UTF8_INFO's)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1184
 * Only if a constant is actually needed and does not already exist
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1185
 * will it be added.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1186
 *
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1187
 * The passed in indexes array will be populated with the resolved indexes.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1188
 * The number of newly added constant pool entries is returned.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1189
 */
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1190
static u2 resolve_utf8_indexes(JfrBigEndianWriter& writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1191
                               const InstanceKlass* ik,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1192
                               u2* const utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1193
                               u2 orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1194
                               const Method* clinit_method,
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1195
                               bool register_klass,
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1196
                               bool untypedEventHandler,
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1197
                               TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1198
  assert(utf8_indexes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1199
  u2 added_cp_entries = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1200
  // resolve all required symbols
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1201
  for (u2 index = 0; index < NOF_UTF8_REQ_SYMBOLS; ++index) {
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1202
    utf8_indexes[index] = find_or_add_utf8_info(writer, ik, utf8_constants[index], orig_cp_len, added_cp_entries, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1203
  }
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1204
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1205
  // resolve optional constants
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1206
  utf8_indexes[UTF8_OPT_eventHandler_FIELD_DESC] = untypedEventHandler ? invalid_cp_index :
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1207
    find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_eventHandler_FIELD_DESC], orig_cp_len, added_cp_entries, THREAD);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1208
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1209
  utf8_indexes[UTF8_OPT_LjavaLangObject] = untypedEventHandler ?
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1210
    find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_LjavaLangObject], orig_cp_len, added_cp_entries, THREAD) : invalid_cp_index;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1211
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1212
  if (register_klass) {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1213
    utf8_indexes[UTF8_OPT_clinit] =
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1214
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_clinit], orig_cp_len, added_cp_entries, THREAD);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1215
    utf8_indexes[UTF8_OPT_FlightRecorder] =
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1216
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_FlightRecorder], orig_cp_len, added_cp_entries, THREAD);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1217
    utf8_indexes[UTF8_OPT_register] =
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1218
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_register], orig_cp_len, added_cp_entries, THREAD);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1219
    utf8_indexes[UTF8_OPT_CLASS_VOID_METHOD_DESC] =
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1220
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_CLASS_VOID_METHOD_DESC], orig_cp_len, added_cp_entries, THREAD);
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1221
  } else {
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1222
    utf8_indexes[UTF8_OPT_clinit] = invalid_cp_index;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1223
    utf8_indexes[UTF8_OPT_FlightRecorder] = invalid_cp_index;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1224
    utf8_indexes[UTF8_OPT_register] = invalid_cp_index;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1225
    utf8_indexes[UTF8_OPT_CLASS_VOID_METHOD_DESC] = invalid_cp_index;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1226
  }
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1227
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1228
  if (clinit_method != NULL && clinit_method->has_stackmap_table()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1229
    utf8_indexes[UTF8_OPT_StackMapTable] =
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1230
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_StackMapTable], orig_cp_len, added_cp_entries, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1231
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1232
    utf8_indexes[UTF8_OPT_StackMapTable] = invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1233
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1234
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1235
  if (clinit_method != NULL && clinit_method->has_linenumber_table()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1236
    utf8_indexes[UTF8_OPT_LineNumberTable] =
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1237
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_LineNumberTable], orig_cp_len, added_cp_entries, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1238
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1239
    utf8_indexes[UTF8_OPT_LineNumberTable] = invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1240
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1241
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1242
  if (clinit_method != NULL && clinit_method->has_localvariable_table()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1243
    utf8_indexes[UTF8_OPT_LocalVariableTable] =
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1244
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_LocalVariableTable], orig_cp_len, added_cp_entries, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1245
    utf8_indexes[UTF8_OPT_LocalVariableTypeTable] =
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1246
      find_or_add_utf8_info(writer, ik, utf8_constants[UTF8_OPT_LocalVariableTypeTable], orig_cp_len, added_cp_entries, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1247
  } else {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1248
    utf8_indexes[UTF8_OPT_LocalVariableTable] = invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1249
    utf8_indexes[UTF8_OPT_LocalVariableTypeTable] = invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1250
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1251
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1252
  return added_cp_entries;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1253
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1254
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1255
static u1* new_bytes_for_lazy_instrumentation(const InstanceKlass* ik,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1256
                                              const ClassFileParser& parser,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1257
                                              jint& size_of_new_bytes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1258
                                              TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1259
  assert(ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1260
  // If the class already has a clinit method
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1261
  // we need to take that into account
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1262
  const Method* clinit_method = ik->class_initializer();
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1263
  bool untypedEventHandler = false;
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1264
  const bool register_klass = should_register_klass(ik, untypedEventHandler);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1265
  const ClassFileStream* const orig_stream = parser.clone_stream();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1266
  const int orig_stream_size = orig_stream->length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1267
  assert(orig_stream->current_offset() == 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1268
  const u2 orig_cp_len = position_stream_after_cp(orig_stream);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1269
  assert(orig_cp_len > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1270
  assert(orig_stream->current_offset() > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1271
  // Dimension and allocate a working byte buffer
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1272
  // to be used in building up a modified class [B.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1273
  const jint new_buffer_size = extra_stream_bytes + orig_stream_size;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1274
  u1* const new_buffer = NEW_RESOURCE_ARRAY_IN_THREAD_RETURN_NULL(THREAD, u1, new_buffer_size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1275
  if (new_buffer == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1276
    log_error(jfr, system) ("Thread local allocation (native) for " SIZE_FORMAT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1277
      " bytes failed in JfrClassAdapter::on_klass_creation", (size_t)new_buffer_size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1278
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1279
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1280
  assert(new_buffer != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1281
  // [B wrapped in a big endian writer
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1282
  JfrBigEndianWriter writer(new_buffer, new_buffer_size);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1283
  assert(writer.current_offset() == 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1284
  const u4 orig_access_flag_offset = orig_stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1285
  // Copy original stream from the beginning up to AccessFlags
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1286
  // This means the original constant pool contents are copied unmodified
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1287
  writer.bytes(orig_stream->buffer(), orig_access_flag_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1288
  assert(writer.is_valid(), "invariant");
50123
f222eba39694 8203274: 32-bit build failures after JDK-8199712 (Flight Recorder)
shade
parents: 50113
diff changeset
  1289
  assert(writer.current_offset() == (intptr_t)orig_access_flag_offset, "invariant"); // same positions
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1290
  // Our writer now sits just after the last original constant pool entry.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1291
  // I.e. we are in a good position to append new constant pool entries
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1292
  // This array will contain the resolved indexes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1293
  // in order to reference UTF8_INFO's needed
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1294
  u2 utf8_indexes[NOF_UTF8_SYMBOLS];
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1295
  // Resolve_utf8_indexes will be conservative in attempting to
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1296
  // locate an existing UTF8_INFO; it will only append constants
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1297
  // that is absolutely required
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1298
  u2 number_of_new_constants =
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1299
    resolve_utf8_indexes(writer, ik, utf8_indexes, orig_cp_len, clinit_method, register_klass, untypedEventHandler, THREAD);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1300
  // UTF8_INFO entries now added to the constant pool
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1301
  // In order to invoke a method we would need additional
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1302
  // constants, JVM_CONSTANT_Class, JVM_CONSTANT_NameAndType
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1303
  // and JVM_CONSTANT_Methodref.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1304
  const u2 flr_register_method_ref_index =
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1305
    register_klass ?
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1306
      add_flr_register_method_constants(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1307
                                        utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1308
                                        orig_cp_len,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1309
                                        number_of_new_constants,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1310
                                        THREAD) :  invalid_cp_index;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1311
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1312
  // New constant pool entries added and all UTF8_INFO indexes resolved
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1313
  // Now update the class file constant_pool_count with an updated count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1314
  writer.write_at_offset<u2>(orig_cp_len + number_of_new_constants, 8);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1315
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1316
  orig_stream->skip_u2_fast(3); // access_flags, this_class_index, super_class_index
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1317
  const u2 iface_len = orig_stream->get_u2_fast(); // interfaces
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1318
  orig_stream->skip_u2_fast(iface_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1319
  const u4 orig_fields_len_offset = orig_stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1320
  // Copy from AccessFlags up to and including interfaces
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1321
  writer.bytes(orig_stream->buffer() + orig_access_flag_offset,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1322
               orig_fields_len_offset - orig_access_flag_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1323
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1324
  const jlong new_fields_len_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1325
  const u2 orig_fields_len = position_stream_after_fields(orig_stream);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1326
  u4 orig_method_len_offset = orig_stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1327
  // Copy up to and including fields
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1328
  writer.bytes(orig_stream->buffer() + orig_fields_len_offset, orig_method_len_offset - orig_fields_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1329
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1330
  // We are sitting just after the original number of field_infos
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1331
  // so this is a position where we can add (append) new field_infos
52334
a181612f0715 8203629: Produce events in the JDK without a dependency on jdk.jfr
egahlin
parents: 51334
diff changeset
  1332
  const u2 number_of_new_fields = add_field_infos(writer, utf8_indexes, untypedEventHandler);
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1333
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1334
  const jlong new_method_len_offset = writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1335
  // Additional field_infos added, update classfile fields_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1336
  writer.write_at_offset<u2>(orig_fields_len + number_of_new_fields, new_fields_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1337
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1338
  // Our current location is now at classfile methods_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1339
  const u2 orig_methods_len = position_stream_after_methods(writer,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1340
                                                            orig_stream,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1341
                                                            utf8_indexes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1342
                                                            register_klass,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1343
                                                            clinit_method,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1344
                                                            orig_method_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1345
  const u4 orig_attributes_count_offset = orig_stream->current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1346
  // Copy existing methods
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1347
  writer.bytes(orig_stream->buffer() + orig_method_len_offset, orig_attributes_count_offset - orig_method_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1348
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1349
  // We are sitting just after the original number of method_infos
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1350
  // so this is a position where we can add (append) new method_infos
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1351
  u2 number_of_new_methods = add_method_infos(writer, utf8_indexes);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1352
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1353
  // We have just added the new methods.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1354
  //
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1355
  // What about the state of <clinit>?
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1356
  // We would need to do:
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1357
  // 1. Nothing (@Registered(false) annotation)
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1358
  // 2. Build up a new <clinit> - and if the original class already contains a <clinit>,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1359
  //                              merging will be neccessary.
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1360
  //
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1361
  if (register_klass) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1362
    insert_clinit_method(ik, parser, writer, orig_cp_len, utf8_indexes, flr_register_method_ref_index, clinit_method, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1363
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1364
  number_of_new_methods += clinit_method != NULL ? 0 : register_klass ? 1 : 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1365
  // Update classfile methods_count
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1366
  writer.write_at_offset<u2>(orig_methods_len + number_of_new_methods, new_method_len_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1367
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1368
  // Copy last remaining bytes
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1369
  writer.bytes(orig_stream->buffer() + orig_attributes_count_offset, orig_stream_size - orig_attributes_count_offset);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1370
  assert(writer.is_valid(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1371
  assert(writer.current_offset() > orig_stream->length(), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1372
  size_of_new_bytes = (jint)writer.current_offset();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1373
  return new_buffer;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1374
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1375
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1376
static void log_pending_exception(oop throwable) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1377
  assert(throwable != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1378
  oop msg = java_lang_Throwable::message(throwable);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1379
  if (msg != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1380
    char* text = java_lang_String::as_utf8_string(msg);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1381
    if (text != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1382
      log_error(jfr, system) ("%s", text);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1383
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1384
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1385
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1386
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1387
static bool should_force_instrumentation() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1388
  return !JfrOptionSet::allow_event_retransforms() || JfrEventClassTransformer::is_force_instrumentation();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1389
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1390
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1391
static ClassFileStream* create_new_bytes_for_subklass(const InstanceKlass* ik, const ClassFileParser& parser, Thread* t) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1392
  assert(JdkJfrEvent::is_a(ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1393
  DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(t));
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1394
  jint size_of_new_bytes = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1395
  const u1* new_bytes = new_bytes_for_lazy_instrumentation(ik, parser, size_of_new_bytes, t);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1396
  if (new_bytes == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1397
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1398
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1399
  assert(new_bytes != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1400
  assert(size_of_new_bytes > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1401
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1402
  bool force_instrumentation = should_force_instrumentation();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1403
  if (Jfr::is_recording() || force_instrumentation) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1404
    jint size_instrumented_data = 0;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1405
    unsigned char* instrumented_data = NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1406
    const jclass super = (jclass)JNIHandles::make_local(ik->super()->java_mirror());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1407
    JfrUpcalls::new_bytes_eager_instrumentation(TRACE_ID(ik),
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1408
                                                force_instrumentation,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1409
                                                super,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1410
                                                size_of_new_bytes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1411
                                                new_bytes,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1412
                                                &size_instrumented_data,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1413
                                                &instrumented_data,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1414
                                                t);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1415
    if (t->has_pending_exception()) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1416
      log_pending_exception(t->pending_exception());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1417
      t->clear_pending_exception();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1418
      return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1419
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1420
    assert(instrumented_data != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1421
    assert(size_instrumented_data > 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1422
    return new ClassFileStream(instrumented_data, size_instrumented_data, NULL, ClassFileStream::verify);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1423
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1424
  return new ClassFileStream(new_bytes, size_of_new_bytes, NULL, ClassFileStream::verify);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1425
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1426
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1427
static bool cache_bytes(InstanceKlass* ik, ClassFileStream* new_stream, InstanceKlass* new_ik, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1428
  assert(ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1429
  assert(new_ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1430
  assert(new_ik->name() != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1431
  assert(new_stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1432
  assert(!HAS_PENDING_EXCEPTION, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1433
  static const bool can_retransform = JfrOptionSet::allow_retransforms();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1434
  if (!can_retransform) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1435
    return true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1436
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1437
  const jint stream_len = new_stream->length();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1438
  JvmtiCachedClassFileData* p =
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1439
    (JvmtiCachedClassFileData*)NEW_C_HEAP_ARRAY_RETURN_NULL(u1, offset_of(JvmtiCachedClassFileData, data) + stream_len, mtInternal);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1440
  if (p == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1441
    log_error(jfr, system)("Allocation using C_HEAP_ARRAY for " SIZE_FORMAT
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1442
      " bytes failed in JfrClassAdapter::on_klass_creation", (size_t)offset_of(JvmtiCachedClassFileData, data) + stream_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1443
    return false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1444
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1445
  p->length = stream_len;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1446
  memcpy(p->data, new_stream->buffer(), stream_len);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1447
  new_ik->set_cached_class_file(p);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1448
  JvmtiCachedClassFileData* const cached_class_data = ik->get_cached_class_file();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1449
  if (cached_class_data != NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1450
    os::free(cached_class_data);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1451
    ik->set_cached_class_file(NULL);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1452
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1453
  return true;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1454
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1455
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1456
static InstanceKlass* create_new_instance_klass(InstanceKlass* ik, ClassFileStream* stream, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1457
  assert(stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1458
  ResourceMark rm(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1459
  ClassLoaderData* const cld = ik->class_loader_data();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1460
  Handle pd(THREAD, ik->protection_domain());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1461
  Symbol* const class_name = ik->name();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1462
  const char* const klass_name = class_name != NULL ? class_name->as_C_string() : "";
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1463
  ClassFileParser new_parser(stream,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1464
                             class_name,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1465
                             cld,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1466
                             pd,
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1467
                             NULL, // host klass
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1468
                             NULL, // cp_patches
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1469
                             ClassFileParser::INTERNAL, // internal visibility
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1470
                             THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1471
  if (HAS_PENDING_EXCEPTION) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1472
    log_pending_exception(PENDING_EXCEPTION);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1473
    CLEAR_PENDING_EXCEPTION;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1474
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1475
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1476
  InstanceKlass* const new_ik = new_parser.create_instance_klass(false, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1477
  if (HAS_PENDING_EXCEPTION) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1478
    log_pending_exception(PENDING_EXCEPTION);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1479
    CLEAR_PENDING_EXCEPTION;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1480
    return NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1481
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1482
  assert(new_ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1483
  assert(new_ik->name() != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1484
  assert(strncmp(ik->name()->as_C_string(), new_ik->name()->as_C_string(), strlen(ik->name()->as_C_string())) == 0, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1485
  return cache_bytes(ik, stream, new_ik, THREAD) ? new_ik : NULL;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1486
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1487
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1488
static void rewrite_klass_pointer(InstanceKlass*& ik, InstanceKlass* new_ik, ClassFileParser& parser, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1489
  assert(ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1490
  assert(new_ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1491
  assert(new_ik->name() != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1492
  assert(JdkJfrEvent::is(new_ik) || JdkJfrEvent::is_subklass(new_ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1493
  assert(!HAS_PENDING_EXCEPTION, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1494
  // assign original InstanceKlass* back onto "its" parser object for proper destruction
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1495
  parser.set_klass_to_deallocate(ik);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1496
  // now rewrite original pointer to newly created InstanceKlass
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1497
  ik = new_ik;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1498
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1499
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1500
static bool is_retransforming(const InstanceKlass* ik, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1501
  assert(ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1502
  assert(JdkJfrEvent::is_a(ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1503
  Symbol* const name = ik->name();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1504
  assert(name != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1505
  Handle class_loader(THREAD, ik->class_loader());
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1506
  Handle protection_domain(THREAD, ik->protection_domain());
58823
mgronlun
parents: 58157
diff changeset
  1507
  return SystemDictionary::find(name, class_loader, protection_domain, THREAD) != NULL;
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1508
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1509
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1510
// target for JFR_ON_KLASS_CREATION hook
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1511
void JfrEventClassTransformer::on_klass_creation(InstanceKlass*& ik, ClassFileParser& parser, TRAPS) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1512
  assert(ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1513
  if (JdkJfrEvent::is(ik)) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1514
    ResourceMark rm(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1515
    HandleMark hm(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1516
    ClassFileStream* new_stream = create_new_bytes_for_event_klass(ik, parser, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1517
    if (new_stream == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1518
      log_error(jfr, system)("JfrClassAdapter: unable to create ClassFileStream");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1519
      return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1520
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1521
    assert(new_stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1522
    InstanceKlass* new_ik = create_new_instance_klass(ik, new_stream, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1523
    if (new_ik == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1524
      log_error(jfr, system)("JfrClassAdapter: unable to create InstanceKlass");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1525
      return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1526
    }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1527
    assert(new_ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1528
    // We now need to explicitly tag the replaced klass as the jdk.jfr.Event klass
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1529
    assert(!JdkJfrEvent::is(new_ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1530
    JdkJfrEvent::tag_as(new_ik);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1531
    assert(JdkJfrEvent::is(new_ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1532
    rewrite_klass_pointer(ik, new_ik, parser, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1533
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1534
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1535
  assert(JdkJfrEvent::is_subklass(ik), "invariant");
58823
mgronlun
parents: 58157
diff changeset
  1536
  if (ik->is_abstract() || is_retransforming(ik, THREAD)) {
mgronlun
parents: 58157
diff changeset
  1537
    // abstract and scratch classes are not instrumented
50113
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1538
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1539
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1540
  ResourceMark rm(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1541
  HandleMark hm(THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1542
  ClassFileStream* const new_stream = create_new_bytes_for_subklass(ik, parser, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1543
  if (NULL == new_stream) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1544
    log_error(jfr, system)("JfrClassAdapter: unable to create ClassFileStream");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1545
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1546
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1547
  assert(new_stream != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1548
  InstanceKlass* new_ik = create_new_instance_klass(ik, new_stream, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1549
  if (new_ik == NULL) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1550
    log_error(jfr, system)("JfrClassAdapter: unable to create InstanceKlass");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1551
    return;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1552
  }
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1553
  assert(new_ik != NULL, "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1554
  // would have been tagged already as a subklass during the normal process of traceid assignment
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1555
  assert(JdkJfrEvent::is_subklass(new_ik), "invariant");
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1556
  traceid id = ik->trace_id();
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1557
  ik->set_trace_id(0);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1558
  new_ik->set_trace_id(id);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1559
  rewrite_klass_pointer(ik, new_ik, parser, THREAD);
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1560
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1561
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1562
static bool _force_instrumentation = false;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1563
void JfrEventClassTransformer::set_force_instrumentation(bool force_instrumentation) {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1564
  _force_instrumentation = force_instrumentation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1565
}
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1566
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1567
bool JfrEventClassTransformer::is_force_instrumentation() {
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1568
  return _force_instrumentation;
caf115bb98ad 8199712: Flight Recorder
egahlin
parents:
diff changeset
  1569
}