src/share/vm/classfile/verifier.hpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6871
077483254bf6
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial