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 | /* |
drchase@6680 | 2 | * Copyright (c) 1998, 2014, 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_VERIFIER_HPP |
stefank@2314 | 26 | #define SHARE_VM_CLASSFILE_VERIFIER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "classfile/verificationType.hpp" |
stefank@2314 | 29 | #include "memory/gcLocker.hpp" |
stefank@2314 | 30 | #include "oops/klass.hpp" |
coleenp@4037 | 31 | #include "oops/method.hpp" |
stefank@2314 | 32 | #include "runtime/handles.hpp" |
hseigel@6871 | 33 | #include "utilities/growableArray.hpp" |
stefank@2314 | 34 | #include "utilities/exceptions.hpp" |
stefank@2314 | 35 | |
duke@435 | 36 | // The verifier class |
duke@435 | 37 | class Verifier : AllStatic { |
duke@435 | 38 | public: |
jrose@1957 | 39 | enum { |
hseigel@5213 | 40 | STRICTER_ACCESS_CTRL_CHECK_VERSION = 49, |
jrose@1957 | 41 | STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50, |
hseigel@5213 | 42 | INVOKEDYNAMIC_MAJOR_VERSION = 51, |
hseigel@5213 | 43 | NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52 |
jrose@1957 | 44 | }; |
duke@435 | 45 | typedef enum { ThrowException, NoException } Mode; |
duke@435 | 46 | |
duke@435 | 47 | /** |
duke@435 | 48 | * Verify the bytecodes for a class. If 'throw_exception' is true |
duke@435 | 49 | * then the appropriate VerifyError or ClassFormatError will be thrown. |
duke@435 | 50 | * Otherwise, no exception is thrown and the return indicates the |
duke@435 | 51 | * error. |
duke@435 | 52 | */ |
acorn@1408 | 53 | static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS); |
duke@435 | 54 | |
acorn@1408 | 55 | // Return false if the class is loaded by the bootstrap loader, |
acorn@1408 | 56 | // or if defineClass was called requesting skipping verification |
acorn@1408 | 57 | // -Xverify:all/none override this value |
acorn@1408 | 58 | static bool should_verify_for(oop class_loader, bool should_verify_class); |
duke@435 | 59 | |
duke@435 | 60 | // Relax certain verifier checks to enable some broken 1.1 apps to run on 1.2. |
duke@435 | 61 | static bool relax_verify_for(oop class_loader); |
duke@435 | 62 | |
duke@435 | 63 | private: |
acorn@1408 | 64 | static bool is_eligible_for_verification(instanceKlassHandle klass, bool should_verify_class); |
coleenp@2497 | 65 | static Symbol* inference_verify( |
duke@435 | 66 | instanceKlassHandle klass, char* msg, size_t msg_len, TRAPS); |
duke@435 | 67 | }; |
duke@435 | 68 | |
duke@435 | 69 | class RawBytecodeStream; |
duke@435 | 70 | class StackMapFrame; |
duke@435 | 71 | class StackMapTable; |
duke@435 | 72 | |
duke@435 | 73 | // Summary of verifier's memory usage: |
duke@435 | 74 | // StackMapTable is stack allocated. |
coleenp@2497 | 75 | // StackMapFrame are resource allocated. There is only one ResourceMark |
coleenp@2497 | 76 | // for each class verification, which is created at the top level. |
duke@435 | 77 | // There is one mutable StackMapFrame (current_frame) which is updated |
duke@435 | 78 | // by abstract bytecode interpretation. frame_in_exception_handler() returns |
duke@435 | 79 | // a frame that has a mutable one-item stack (ready for pushing the |
duke@435 | 80 | // catch type exception object). All the other StackMapFrame's |
duke@435 | 81 | // are immutable (including their locals and stack arrays) after |
duke@435 | 82 | // their constructions. |
duke@435 | 83 | // locals/stack arrays in StackMapFrame are resource allocated. |
duke@435 | 84 | // locals/stack arrays can be shared between StackMapFrame's, except |
duke@435 | 85 | // the mutable StackMapFrame (current_frame). |
duke@435 | 86 | |
duke@435 | 87 | // These macros are used similarly to CHECK macros but also check |
duke@435 | 88 | // the status of the verifier and return if that has an error. |
duke@435 | 89 | #define CHECK_VERIFY(verifier) \ |
ccheung@5259 | 90 | CHECK); if ((verifier)->has_error()) return; ((void)0 |
duke@435 | 91 | #define CHECK_VERIFY_(verifier, result) \ |
ccheung@5259 | 92 | CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0 |
duke@435 | 93 | |
kamg@3992 | 94 | class TypeOrigin VALUE_OBJ_CLASS_SPEC { |
kamg@3992 | 95 | private: |
kamg@3992 | 96 | typedef enum { |
kamg@3992 | 97 | CF_LOCALS, // Comes from the current frame locals |
kamg@3992 | 98 | CF_STACK, // Comes from the current frame expression stack |
kamg@3992 | 99 | SM_LOCALS, // Comes from stackmap locals |
kamg@3992 | 100 | SM_STACK, // Comes from stackmap expression stack |
kamg@3992 | 101 | CONST_POOL, // Comes from the constant pool |
kamg@3992 | 102 | SIG, // Comes from method signature |
kamg@3992 | 103 | IMPLICIT, // Comes implicitly from code or context |
kamg@3992 | 104 | BAD_INDEX, // No type, but the index is bad |
kamg@3992 | 105 | FRAME_ONLY, // No type, context just contains the frame |
kamg@3992 | 106 | NONE |
kamg@3992 | 107 | } Origin; |
kamg@3992 | 108 | |
kamg@3992 | 109 | Origin _origin; |
kamg@3992 | 110 | u2 _index; // local, stack, or constant pool index |
kamg@3992 | 111 | StackMapFrame* _frame; // source frame if CF or SM |
kamg@3992 | 112 | VerificationType _type; // The actual type |
kamg@3992 | 113 | |
kamg@3992 | 114 | TypeOrigin( |
kamg@3992 | 115 | Origin origin, u2 index, StackMapFrame* frame, VerificationType type) |
kamg@3992 | 116 | : _origin(origin), _index(index), _frame(frame), _type(type) {} |
kamg@3992 | 117 | |
kamg@3992 | 118 | public: |
kamg@3992 | 119 | TypeOrigin() : _origin(NONE), _index(0), _frame(NULL) {} |
kamg@3992 | 120 | |
kamg@3992 | 121 | static TypeOrigin null(); |
kamg@3992 | 122 | static TypeOrigin local(u2 index, StackMapFrame* frame); |
kamg@3992 | 123 | static TypeOrigin stack(u2 index, StackMapFrame* frame); |
kamg@3992 | 124 | static TypeOrigin sm_local(u2 index, StackMapFrame* frame); |
kamg@3992 | 125 | static TypeOrigin sm_stack(u2 index, StackMapFrame* frame); |
kamg@3992 | 126 | static TypeOrigin cp(u2 index, VerificationType vt); |
kamg@3992 | 127 | static TypeOrigin signature(VerificationType vt); |
kamg@3992 | 128 | static TypeOrigin bad_index(u2 index); |
kamg@3992 | 129 | static TypeOrigin implicit(VerificationType t); |
kamg@3992 | 130 | static TypeOrigin frame(StackMapFrame* frame); |
kamg@3992 | 131 | |
kamg@3992 | 132 | void reset_frame(); |
kamg@3992 | 133 | void details(outputStream* ss) const; |
kamg@3992 | 134 | void print_frame(outputStream* ss) const; |
kamg@3992 | 135 | const StackMapFrame* frame() const { return _frame; } |
kamg@3992 | 136 | bool is_valid() const { return _origin != NONE; } |
kamg@3992 | 137 | u2 index() const { return _index; } |
kamg@3992 | 138 | |
kamg@3992 | 139 | #ifdef ASSERT |
kamg@3992 | 140 | void print_on(outputStream* str) const; |
kamg@3992 | 141 | #endif |
kamg@3992 | 142 | }; |
kamg@3992 | 143 | |
kamg@3992 | 144 | class ErrorContext VALUE_OBJ_CLASS_SPEC { |
kamg@3992 | 145 | private: |
kamg@3992 | 146 | typedef enum { |
kamg@3992 | 147 | INVALID_BYTECODE, // There was a problem with the bytecode |
kamg@3992 | 148 | WRONG_TYPE, // Type value was not as expected |
kamg@3992 | 149 | FLAGS_MISMATCH, // Frame flags are not assignable |
kamg@3992 | 150 | BAD_CP_INDEX, // Invalid constant pool index |
kamg@3992 | 151 | BAD_LOCAL_INDEX, // Invalid local index |
kamg@3992 | 152 | LOCALS_SIZE_MISMATCH, // Frames have differing local counts |
kamg@3992 | 153 | STACK_SIZE_MISMATCH, // Frames have different stack sizes |
kamg@3992 | 154 | STACK_OVERFLOW, // Attempt to push onto a full expression stack |
kamg@3992 | 155 | STACK_UNDERFLOW, // Attempt to pop and empty expression stack |
kamg@3992 | 156 | MISSING_STACKMAP, // No stackmap for this location and there should be |
kamg@3992 | 157 | BAD_STACKMAP, // Format error in stackmap |
kamg@3992 | 158 | NO_FAULT, // No error |
kamg@3992 | 159 | UNKNOWN |
kamg@3992 | 160 | } FaultType; |
kamg@3992 | 161 | |
kamg@3992 | 162 | int _bci; |
kamg@3992 | 163 | FaultType _fault; |
kamg@3992 | 164 | TypeOrigin _type; |
kamg@3992 | 165 | TypeOrigin _expected; |
kamg@3992 | 166 | |
kamg@3992 | 167 | ErrorContext(int bci, FaultType fault) : |
kamg@3992 | 168 | _bci(bci), _fault(fault) {} |
kamg@3992 | 169 | ErrorContext(int bci, FaultType fault, TypeOrigin type) : |
kamg@3992 | 170 | _bci(bci), _fault(fault), _type(type) {} |
kamg@3992 | 171 | ErrorContext(int bci, FaultType fault, TypeOrigin type, TypeOrigin exp) : |
kamg@3992 | 172 | _bci(bci), _fault(fault), _type(type), _expected(exp) {} |
kamg@3992 | 173 | |
kamg@3992 | 174 | public: |
kamg@3992 | 175 | ErrorContext() : _bci(-1), _fault(NO_FAULT) {} |
kamg@3992 | 176 | |
kamg@3992 | 177 | static ErrorContext bad_code(u2 bci) { |
kamg@3992 | 178 | return ErrorContext(bci, INVALID_BYTECODE); |
kamg@3992 | 179 | } |
kamg@3992 | 180 | static ErrorContext bad_type(u2 bci, TypeOrigin type) { |
kamg@3992 | 181 | return ErrorContext(bci, WRONG_TYPE, type); |
kamg@3992 | 182 | } |
kamg@3992 | 183 | static ErrorContext bad_type(u2 bci, TypeOrigin type, TypeOrigin exp) { |
kamg@3992 | 184 | return ErrorContext(bci, WRONG_TYPE, type, exp); |
kamg@3992 | 185 | } |
kamg@3992 | 186 | static ErrorContext bad_flags(u2 bci, StackMapFrame* frame) { |
kamg@3992 | 187 | return ErrorContext(bci, FLAGS_MISMATCH, TypeOrigin::frame(frame)); |
kamg@3992 | 188 | } |
kamg@3992 | 189 | static ErrorContext bad_flags(u2 bci, StackMapFrame* cur, StackMapFrame* sm) { |
kamg@3992 | 190 | return ErrorContext(bci, FLAGS_MISMATCH, |
kamg@3992 | 191 | TypeOrigin::frame(cur), TypeOrigin::frame(sm)); |
kamg@3992 | 192 | } |
kamg@3992 | 193 | static ErrorContext bad_cp_index(u2 bci, u2 index) { |
kamg@3992 | 194 | return ErrorContext(bci, BAD_CP_INDEX, TypeOrigin::bad_index(index)); |
kamg@3992 | 195 | } |
kamg@3992 | 196 | static ErrorContext bad_local_index(u2 bci, u2 index) { |
kamg@3992 | 197 | return ErrorContext(bci, BAD_LOCAL_INDEX, TypeOrigin::bad_index(index)); |
kamg@3992 | 198 | } |
kamg@3992 | 199 | static ErrorContext locals_size_mismatch( |
kamg@3992 | 200 | u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) { |
kamg@3992 | 201 | return ErrorContext(bci, LOCALS_SIZE_MISMATCH, |
kamg@3992 | 202 | TypeOrigin::frame(frame0), TypeOrigin::frame(frame1)); |
kamg@3992 | 203 | } |
kamg@3992 | 204 | static ErrorContext stack_size_mismatch( |
kamg@3992 | 205 | u2 bci, StackMapFrame* frame0, StackMapFrame* frame1) { |
kamg@3992 | 206 | return ErrorContext(bci, STACK_SIZE_MISMATCH, |
kamg@3992 | 207 | TypeOrigin::frame(frame0), TypeOrigin::frame(frame1)); |
kamg@3992 | 208 | } |
kamg@3992 | 209 | static ErrorContext stack_overflow(u2 bci, StackMapFrame* frame) { |
kamg@3992 | 210 | return ErrorContext(bci, STACK_OVERFLOW, TypeOrigin::frame(frame)); |
kamg@3992 | 211 | } |
kamg@3992 | 212 | static ErrorContext stack_underflow(u2 bci, StackMapFrame* frame) { |
kamg@3992 | 213 | return ErrorContext(bci, STACK_UNDERFLOW, TypeOrigin::frame(frame)); |
kamg@3992 | 214 | } |
kamg@3992 | 215 | static ErrorContext missing_stackmap(u2 bci) { |
kamg@3992 | 216 | return ErrorContext(bci, MISSING_STACKMAP); |
kamg@3992 | 217 | } |
kamg@3992 | 218 | static ErrorContext bad_stackmap(int index, StackMapFrame* frame) { |
kamg@3992 | 219 | return ErrorContext(0, BAD_STACKMAP, TypeOrigin::frame(frame)); |
kamg@3992 | 220 | } |
kamg@3992 | 221 | |
kamg@3992 | 222 | bool is_valid() const { return _fault != NO_FAULT; } |
kamg@3992 | 223 | int bci() const { return _bci; } |
kamg@3992 | 224 | |
kamg@3992 | 225 | void reset_frames() { |
kamg@3992 | 226 | _type.reset_frame(); |
kamg@3992 | 227 | _expected.reset_frame(); |
kamg@3992 | 228 | } |
kamg@3992 | 229 | |
minqi@5097 | 230 | void details(outputStream* ss, const Method* method) const; |
kamg@3992 | 231 | |
kamg@3992 | 232 | #ifdef ASSERT |
kamg@3992 | 233 | void print_on(outputStream* str) const { |
kamg@3992 | 234 | str->print("error_context(%d, %d,", _bci, _fault); |
kamg@3992 | 235 | _type.print_on(str); |
kamg@3992 | 236 | str->print(","); |
kamg@3992 | 237 | _expected.print_on(str); |
kamg@3992 | 238 | str->print(")"); |
kamg@3992 | 239 | } |
kamg@3992 | 240 | #endif |
kamg@3992 | 241 | |
kamg@3992 | 242 | private: |
minqi@5097 | 243 | void location_details(outputStream* ss, const Method* method) const; |
kamg@3992 | 244 | void reason_details(outputStream* ss) const; |
kamg@3992 | 245 | void frame_details(outputStream* ss) const; |
minqi@5097 | 246 | void bytecode_details(outputStream* ss, const Method* method) const; |
minqi@5097 | 247 | void handler_details(outputStream* ss, const Method* method) const; |
minqi@5097 | 248 | void stackmap_details(outputStream* ss, const Method* method) const; |
kamg@3992 | 249 | }; |
kamg@3992 | 250 | |
duke@435 | 251 | // A new instance of this class is created for each class being verified |
duke@435 | 252 | class ClassVerifier : public StackObj { |
duke@435 | 253 | private: |
duke@435 | 254 | Thread* _thread; |
kamg@3992 | 255 | GrowableArray<Symbol*>* _symbols; // keep a list of symbols created |
kamg@3992 | 256 | |
coleenp@2497 | 257 | Symbol* _exception_type; |
duke@435 | 258 | char* _message; |
kamg@3992 | 259 | |
kamg@3992 | 260 | ErrorContext _error_context; // contains information about an error |
duke@435 | 261 | |
duke@435 | 262 | void verify_method(methodHandle method, TRAPS); |
duke@435 | 263 | char* generate_code_data(methodHandle m, u4 code_length, TRAPS); |
kamg@3992 | 264 | void verify_exception_handler_table(u4 code_length, char* code_data, |
kamg@3992 | 265 | int& min, int& max, TRAPS); |
duke@435 | 266 | void verify_local_variable_table(u4 code_length, char* code_data, TRAPS); |
duke@435 | 267 | |
duke@435 | 268 | VerificationType cp_ref_index_to_type( |
duke@435 | 269 | int index, constantPoolHandle cp, TRAPS) { |
duke@435 | 270 | return cp_index_to_type(cp->klass_ref_index_at(index), cp, THREAD); |
duke@435 | 271 | } |
duke@435 | 272 | |
duke@435 | 273 | bool is_protected_access( |
coleenp@4037 | 274 | instanceKlassHandle this_class, Klass* target_class, |
coleenp@2497 | 275 | Symbol* field_name, Symbol* field_sig, bool is_method); |
duke@435 | 276 | |
kamg@3992 | 277 | void verify_cp_index(u2 bci, constantPoolHandle cp, int index, TRAPS); |
kamg@3992 | 278 | void verify_cp_type(u2 bci, int index, constantPoolHandle cp, |
kamg@3992 | 279 | unsigned int types, TRAPS); |
kamg@3992 | 280 | void verify_cp_class_type(u2 bci, int index, constantPoolHandle cp, TRAPS); |
duke@435 | 281 | |
duke@435 | 282 | u2 verify_stackmap_table( |
duke@435 | 283 | u2 stackmap_index, u2 bci, StackMapFrame* current_frame, |
duke@435 | 284 | StackMapTable* stackmap_table, bool no_control_flow, TRAPS); |
duke@435 | 285 | |
duke@435 | 286 | void verify_exception_handler_targets( |
duke@435 | 287 | u2 bci, bool this_uninit, StackMapFrame* current_frame, |
duke@435 | 288 | StackMapTable* stackmap_table, TRAPS); |
duke@435 | 289 | |
duke@435 | 290 | void verify_ldc( |
duke@435 | 291 | int opcode, u2 index, StackMapFrame *current_frame, |
duke@435 | 292 | constantPoolHandle cp, u2 bci, TRAPS); |
duke@435 | 293 | |
duke@435 | 294 | void verify_switch( |
duke@435 | 295 | RawBytecodeStream* bcs, u4 code_length, char* code_data, |
duke@435 | 296 | StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS); |
duke@435 | 297 | |
duke@435 | 298 | void verify_field_instructions( |
duke@435 | 299 | RawBytecodeStream* bcs, StackMapFrame* current_frame, |
duke@435 | 300 | constantPoolHandle cp, TRAPS); |
duke@435 | 301 | |
duke@435 | 302 | void verify_invoke_init( |
kamg@3992 | 303 | RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type, |
hseigel@7473 | 304 | StackMapFrame* current_frame, u4 code_length, bool in_try_block, |
hseigel@7473 | 305 | bool* this_uninit, constantPoolHandle cp, StackMapTable* stackmap_table, |
hseigel@7473 | 306 | TRAPS); |
duke@435 | 307 | |
hseigel@7643 | 308 | // Used by ends_in_athrow() to push all handlers that contain bci onto the |
hseigel@7643 | 309 | // handler_stack, if the handler has not already been pushed on the stack. |
hseigel@6871 | 310 | void push_handlers(ExceptionTable* exhandlers, |
hseigel@7643 | 311 | GrowableArray<u4>* handler_list, |
hseigel@6871 | 312 | GrowableArray<u4>* handler_stack, |
hseigel@6871 | 313 | u4 bci); |
hseigel@6871 | 314 | |
hseigel@6871 | 315 | // Returns true if all paths starting with start_bc_offset end in athrow |
hseigel@6871 | 316 | // bytecode or loop. |
hseigel@6871 | 317 | bool ends_in_athrow(u4 start_bc_offset); |
hseigel@6871 | 318 | |
duke@435 | 319 | void verify_invoke_instructions( |
duke@435 | 320 | RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame, |
hseigel@7473 | 321 | bool in_try_block, bool* this_uninit, VerificationType return_type, |
hseigel@7473 | 322 | constantPoolHandle cp, StackMapTable* stackmap_table, TRAPS); |
duke@435 | 323 | |
duke@435 | 324 | VerificationType get_newarray_type(u2 index, u2 bci, TRAPS); |
kamg@3992 | 325 | void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp, |
kamg@3992 | 326 | StackMapFrame* current_frame, TRAPS); |
duke@435 | 327 | void verify_return_value( |
kamg@3992 | 328 | VerificationType return_type, VerificationType type, u2 offset, |
kamg@3992 | 329 | StackMapFrame* current_frame, TRAPS); |
duke@435 | 330 | |
duke@435 | 331 | void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 332 | void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 333 | void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 334 | void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 335 | void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 336 | void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 337 | void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 338 | void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 339 | void verify_dstore(u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 340 | void verify_astore(u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 341 | void verify_iinc (u2 index, StackMapFrame* current_frame, TRAPS); |
duke@435 | 342 | |
coleenp@2497 | 343 | bool name_in_supers(Symbol* ref_name, instanceKlassHandle current); |
duke@435 | 344 | |
kamg@2297 | 345 | VerificationType object_type() const; |
kamg@2297 | 346 | |
duke@435 | 347 | instanceKlassHandle _klass; // the class being verified |
duke@435 | 348 | methodHandle _method; // current method being verified |
duke@435 | 349 | VerificationType _this_type; // the verification type of the current class |
duke@435 | 350 | |
jrose@1925 | 351 | // Some recursive calls from the verifier to the name resolver |
jrose@1925 | 352 | // can cause the current class to be re-verified and rewritten. |
jrose@1925 | 353 | // If this happens, the original verification should not continue, |
jrose@1925 | 354 | // because constant pool indexes will have changed. |
jrose@1925 | 355 | // The rewriter is preceded by the verifier. If the verifier throws |
jrose@1925 | 356 | // an error, rewriting is prevented. Also, rewriting always precedes |
jrose@1925 | 357 | // bytecode execution or compilation. Thus, is_rewritten implies |
jrose@1925 | 358 | // that a class has been verified and prepared for execution. |
jrose@1925 | 359 | bool was_recursively_verified() { return _klass->is_rewritten(); } |
jrose@1925 | 360 | |
hseigel@6132 | 361 | bool is_same_or_direct_interface(instanceKlassHandle klass, |
hseigel@6132 | 362 | VerificationType klass_type, VerificationType ref_class_type); |
hseigel@6132 | 363 | |
duke@435 | 364 | public: |
duke@435 | 365 | enum { |
duke@435 | 366 | BYTECODE_OFFSET = 1, |
duke@435 | 367 | NEW_OFFSET = 2 |
duke@435 | 368 | }; |
duke@435 | 369 | |
duke@435 | 370 | // constructor |
kamg@3992 | 371 | ClassVerifier(instanceKlassHandle klass, TRAPS); |
duke@435 | 372 | |
duke@435 | 373 | // destructor |
duke@435 | 374 | ~ClassVerifier(); |
duke@435 | 375 | |
duke@435 | 376 | Thread* thread() { return _thread; } |
duke@435 | 377 | methodHandle method() { return _method; } |
duke@435 | 378 | instanceKlassHandle current_class() const { return _klass; } |
duke@435 | 379 | VerificationType current_type() const { return _this_type; } |
duke@435 | 380 | |
duke@435 | 381 | // Verifies the class. If a verify or class file format error occurs, |
duke@435 | 382 | // the '_exception_name' symbols will set to the exception name and |
duke@435 | 383 | // the message_buffer will be filled in with the exception message. |
duke@435 | 384 | void verify_class(TRAPS); |
duke@435 | 385 | |
duke@435 | 386 | // Return status modes |
coleenp@2497 | 387 | Symbol* result() const { return _exception_type; } |
coleenp@2497 | 388 | bool has_error() const { return result() != NULL; } |
kamg@3992 | 389 | char* exception_message() { |
kamg@3992 | 390 | stringStream ss; |
drchase@6680 | 391 | ss.print("%s", _message); |
kamg@3992 | 392 | _error_context.details(&ss, _method()); |
kamg@3992 | 393 | return ss.as_string(); |
kamg@3992 | 394 | } |
duke@435 | 395 | |
duke@435 | 396 | // Called when verify or class format errors are encountered. |
duke@435 | 397 | // May throw an exception based upon the mode. |
drchase@6680 | 398 | void verify_error(ErrorContext ctx, const char* fmt, ...) ATTRIBUTE_PRINTF(3, 4); |
drchase@6680 | 399 | void class_format_error(const char* fmt, ...) ATTRIBUTE_PRINTF(2, 3); |
duke@435 | 400 | |
coleenp@4037 | 401 | Klass* load_class(Symbol* name, TRAPS); |
duke@435 | 402 | |
duke@435 | 403 | int change_sig_to_verificationType( |
duke@435 | 404 | SignatureStream* sig_type, VerificationType* inference_type, TRAPS); |
duke@435 | 405 | |
duke@435 | 406 | VerificationType cp_index_to_type(int index, constantPoolHandle cp, TRAPS) { |
coleenp@2497 | 407 | return VerificationType::reference_type(cp->klass_name_at(index)); |
duke@435 | 408 | } |
duke@435 | 409 | |
coleenp@2497 | 410 | // Keep a list of temporary symbols created during verification because |
coleenp@2497 | 411 | // their reference counts need to be decrememented when the verifier object |
coleenp@2497 | 412 | // goes out of scope. Since these symbols escape the scope in which they're |
coleenp@2497 | 413 | // created, we can't use a TempNewSymbol. |
kamg@3992 | 414 | Symbol* create_temporary_symbol( |
kamg@3992 | 415 | const Symbol* s, int begin, int end, TRAPS); |
coleenp@2497 | 416 | Symbol* create_temporary_symbol(const char *s, int length, TRAPS); |
coleenp@2497 | 417 | |
kamg@3992 | 418 | TypeOrigin ref_ctx(const char* str, TRAPS); |
hseigel@6761 | 419 | |
duke@435 | 420 | }; |
duke@435 | 421 | |
duke@435 | 422 | inline int ClassVerifier::change_sig_to_verificationType( |
duke@435 | 423 | SignatureStream* sig_type, VerificationType* inference_type, TRAPS) { |
duke@435 | 424 | BasicType bt = sig_type->type(); |
duke@435 | 425 | switch (bt) { |
duke@435 | 426 | case T_OBJECT: |
duke@435 | 427 | case T_ARRAY: |
duke@435 | 428 | { |
coleenp@2497 | 429 | Symbol* name = sig_type->as_symbol(CHECK_0); |
coleenp@2497 | 430 | // Create another symbol to save as signature stream unreferences |
coleenp@2497 | 431 | // this symbol. |
coleenp@2497 | 432 | Symbol* name_copy = |
coleenp@2497 | 433 | create_temporary_symbol(name, 0, name->utf8_length(), CHECK_0); |
coleenp@2497 | 434 | assert(name_copy == name, "symbols don't match"); |
duke@435 | 435 | *inference_type = |
coleenp@2497 | 436 | VerificationType::reference_type(name_copy); |
duke@435 | 437 | return 1; |
duke@435 | 438 | } |
duke@435 | 439 | case T_LONG: |
duke@435 | 440 | *inference_type = VerificationType::long_type(); |
duke@435 | 441 | *++inference_type = VerificationType::long2_type(); |
duke@435 | 442 | return 2; |
duke@435 | 443 | case T_DOUBLE: |
duke@435 | 444 | *inference_type = VerificationType::double_type(); |
duke@435 | 445 | *++inference_type = VerificationType::double2_type(); |
duke@435 | 446 | return 2; |
duke@435 | 447 | case T_INT: |
duke@435 | 448 | case T_BOOLEAN: |
duke@435 | 449 | case T_BYTE: |
duke@435 | 450 | case T_CHAR: |
duke@435 | 451 | case T_SHORT: |
duke@435 | 452 | *inference_type = VerificationType::integer_type(); |
duke@435 | 453 | return 1; |
duke@435 | 454 | case T_FLOAT: |
duke@435 | 455 | *inference_type = VerificationType::float_type(); |
duke@435 | 456 | return 1; |
duke@435 | 457 | default: |
duke@435 | 458 | ShouldNotReachHere(); |
duke@435 | 459 | return 1; |
duke@435 | 460 | } |
duke@435 | 461 | } |
stefank@2314 | 462 | |
stefank@2314 | 463 | #endif // SHARE_VM_CLASSFILE_VERIFIER_HPP |