Mon, 12 Aug 2019 18:30:40 +0300
8223147: JFR Backport
8199712: Flight Recorder
8203346: JFR: Inconsistent signature of jfr_add_string_constant
8195817: JFR.stop should require name of recording
8195818: JFR.start should increase autogenerated name by one
8195819: Remove recording=x from jcmd JFR.check output
8203921: JFR thread sampling is missing fixes from JDK-8194552
8203929: Limit amount of data for JFR.dump
8203664: JFR start failure after AppCDS archive created with JFR StartFlightRecording
8003209: JFR events for network utilization
8207392: [PPC64] Implement JFR profiling
8202835: jfr/event/os/TestSystemProcess.java fails on missing events
Summary: Backport JFR from JDK11. Initial integration
Reviewed-by: neugens
duke@435 | 1 | /* |
kevinw@8703 | 2 | * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP |
stefank@2314 | 26 | #define SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "classfile/stackMapFrame.hpp" |
kamg@3992 | 29 | #include "classfile/verifier.hpp" |
stefank@2314 | 30 | #include "memory/allocation.hpp" |
coleenp@4037 | 31 | #include "oops/constantPool.hpp" |
coleenp@4037 | 32 | #include "oops/method.hpp" |
stefank@2314 | 33 | #include "utilities/globalDefinitions.hpp" |
stefank@2314 | 34 | #ifdef TARGET_ARCH_x86 |
stefank@2314 | 35 | # include "bytes_x86.hpp" |
stefank@2314 | 36 | #endif |
stefank@2314 | 37 | #ifdef TARGET_ARCH_sparc |
stefank@2314 | 38 | # include "bytes_sparc.hpp" |
stefank@2314 | 39 | #endif |
stefank@2314 | 40 | #ifdef TARGET_ARCH_zero |
stefank@2314 | 41 | # include "bytes_zero.hpp" |
stefank@2314 | 42 | #endif |
bobv@2508 | 43 | #ifdef TARGET_ARCH_arm |
bobv@2508 | 44 | # include "bytes_arm.hpp" |
bobv@2508 | 45 | #endif |
bobv@2508 | 46 | #ifdef TARGET_ARCH_ppc |
bobv@2508 | 47 | # include "bytes_ppc.hpp" |
bobv@2508 | 48 | #endif |
stefank@2314 | 49 | |
duke@435 | 50 | class StackMapReader; |
duke@435 | 51 | |
duke@435 | 52 | // StackMapTable class is the StackMap table used by type checker |
duke@435 | 53 | class StackMapTable : public StackObj { |
duke@435 | 54 | private: |
duke@435 | 55 | // Logically, the _frame_count (as well as many fields in the StackFrame) |
duke@435 | 56 | // should be a u2, but if we defined the variable as that type it will |
duke@435 | 57 | // be difficult to detect/recover from overflow or underflow conditions. |
duke@435 | 58 | // Widening the type and making it signed will help detect these. |
duke@435 | 59 | int32_t _code_length; |
duke@435 | 60 | int32_t _frame_count; // Stackmap frame count |
duke@435 | 61 | StackMapFrame** _frame_array; |
duke@435 | 62 | |
duke@435 | 63 | public: |
duke@435 | 64 | StackMapTable(StackMapReader* reader, StackMapFrame* init_frame, |
duke@435 | 65 | u2 max_locals, u2 max_stack, |
duke@435 | 66 | char* code_data, int code_len, TRAPS); |
duke@435 | 67 | |
duke@435 | 68 | inline int32_t get_frame_count() const { return _frame_count; } |
duke@435 | 69 | inline int get_offset(int index) const { |
duke@435 | 70 | return _frame_array[index]->offset(); |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | // Match and/or update current_frame to the frame in stackmap table with |
duke@435 | 74 | // specified offset. Return true if the two frames match. |
duke@435 | 75 | bool match_stackmap( |
duke@435 | 76 | StackMapFrame* current_frame, int32_t offset, |
kevinw@8703 | 77 | bool match, bool update, ErrorContext* ctx, TRAPS) const; |
duke@435 | 78 | // Match and/or update current_frame to the frame in stackmap table with |
duke@435 | 79 | // specified offset and frame index. Return true if the two frames match. |
duke@435 | 80 | bool match_stackmap( |
duke@435 | 81 | StackMapFrame* current_frame, int32_t offset, int32_t frame_index, |
kevinw@8703 | 82 | bool match, bool update, ErrorContext* ctx, TRAPS) const; |
duke@435 | 83 | |
duke@435 | 84 | // Check jump instructions. Make sure there are no uninitialized |
duke@435 | 85 | // instances on backward branch. |
duke@435 | 86 | void check_jump_target(StackMapFrame* frame, int32_t target, TRAPS) const; |
duke@435 | 87 | |
duke@435 | 88 | // The following methods are only used inside this class. |
duke@435 | 89 | |
duke@435 | 90 | // Returns the frame array index where the frame with offset is stored. |
duke@435 | 91 | int get_index_from_offset(int32_t offset) const; |
duke@435 | 92 | |
kamg@3992 | 93 | void print_on(outputStream* str) const; |
duke@435 | 94 | }; |
duke@435 | 95 | |
duke@435 | 96 | class StackMapStream : StackObj { |
duke@435 | 97 | private: |
coleenp@4037 | 98 | Array<u1>* _data; |
duke@435 | 99 | int _index; |
duke@435 | 100 | public: |
coleenp@4037 | 101 | StackMapStream(Array<u1>* ah) |
duke@435 | 102 | : _data(ah), _index(0) { |
duke@435 | 103 | } |
duke@435 | 104 | u1 get_u1(TRAPS) { |
duke@435 | 105 | if (_data == NULL || _index >= _data->length()) { |
duke@435 | 106 | stackmap_format_error("access beyond the end of attribute", CHECK_0); |
duke@435 | 107 | } |
coleenp@4037 | 108 | return _data->at(_index++); |
duke@435 | 109 | } |
duke@435 | 110 | u2 get_u2(TRAPS) { |
duke@435 | 111 | if (_data == NULL || _index >= _data->length() - 1) { |
duke@435 | 112 | stackmap_format_error("access beyond the end of attribute", CHECK_0); |
duke@435 | 113 | } |
coleenp@4037 | 114 | u2 res = Bytes::get_Java_u2(_data->adr_at(_index)); |
duke@435 | 115 | _index += 2; |
duke@435 | 116 | return res; |
duke@435 | 117 | } |
duke@435 | 118 | bool at_end() { |
duke@435 | 119 | return (_data == NULL) || (_index == _data->length()); |
duke@435 | 120 | } |
duke@435 | 121 | static void stackmap_format_error(const char* msg, TRAPS); |
duke@435 | 122 | }; |
duke@435 | 123 | |
duke@435 | 124 | class StackMapReader : StackObj { |
duke@435 | 125 | private: |
duke@435 | 126 | // information about the class and method |
duke@435 | 127 | constantPoolHandle _cp; |
duke@435 | 128 | ClassVerifier* _verifier; |
duke@435 | 129 | StackMapStream* _stream; |
duke@435 | 130 | char* _code_data; |
duke@435 | 131 | int32_t _code_length; |
duke@435 | 132 | |
duke@435 | 133 | // information get from the attribute |
duke@435 | 134 | int32_t _frame_count; // frame count |
duke@435 | 135 | |
duke@435 | 136 | int32_t chop(VerificationType* locals, int32_t length, int32_t chops); |
duke@435 | 137 | VerificationType parse_verification_type(u1* flags, TRAPS); |
duke@435 | 138 | void check_verification_type_array_size( |
duke@435 | 139 | int32_t size, int32_t max_size, TRAPS) { |
duke@435 | 140 | if (size < 0 || size > max_size) { |
duke@435 | 141 | // Since this error could be caused someone rewriting the method |
duke@435 | 142 | // but not knowing to update the stackmap data, we call the the |
duke@435 | 143 | // verifier's error method, which may not throw an exception and |
duke@435 | 144 | // failover to the old verifier instead. |
duke@435 | 145 | _verifier->class_format_error( |
duke@435 | 146 | "StackMapTable format error: bad type array size"); |
duke@435 | 147 | } |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | enum { |
duke@435 | 151 | SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247, |
duke@435 | 152 | SAME_EXTENDED = 251, |
duke@435 | 153 | FULL = 255 |
duke@435 | 154 | }; |
duke@435 | 155 | |
duke@435 | 156 | public: |
duke@435 | 157 | // Constructor |
duke@435 | 158 | StackMapReader(ClassVerifier* v, StackMapStream* stream, char* code_data, |
duke@435 | 159 | int32_t code_len, TRAPS) : |
duke@435 | 160 | _verifier(v), _stream(stream), |
duke@435 | 161 | _code_data(code_data), _code_length(code_len) { |
duke@435 | 162 | methodHandle m = v->method(); |
duke@435 | 163 | if (m->has_stackmap_table()) { |
duke@435 | 164 | _cp = constantPoolHandle(THREAD, m->constants()); |
duke@435 | 165 | _frame_count = _stream->get_u2(CHECK); |
duke@435 | 166 | } else { |
duke@435 | 167 | // There's no stackmap table present. Frame count and size are 0. |
duke@435 | 168 | _frame_count = 0; |
duke@435 | 169 | } |
duke@435 | 170 | } |
duke@435 | 171 | |
duke@435 | 172 | inline int32_t get_frame_count() const { return _frame_count; } |
duke@435 | 173 | StackMapFrame* next(StackMapFrame* pre_frame, bool first, |
duke@435 | 174 | u2 max_locals, u2 max_stack, TRAPS); |
duke@435 | 175 | |
duke@435 | 176 | void check_end(TRAPS) { |
duke@435 | 177 | if (!_stream->at_end()) { |
duke@435 | 178 | StackMapStream::stackmap_format_error("wrong attribute size", CHECK); |
duke@435 | 179 | } |
duke@435 | 180 | } |
duke@435 | 181 | }; |
stefank@2314 | 182 | |
stefank@2314 | 183 | #endif // SHARE_VM_CLASSFILE_STACKMAPTABLE_HPP |