13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP
26 #define SHARE_VM_CLASSFILE_VERIFIER_HPP
27
28 #include "classfile/verificationType.hpp"
29 #include "memory/gcLocker.hpp"
30 #include "oops/klass.hpp"
31 #include "oops/method.hpp"
32 #include "runtime/handles.hpp"
33 #include "utilities/exceptions.hpp"
34
35 // The verifier class
36 class Verifier : AllStatic {
37 public:
38 enum {
39 STRICTER_ACCESS_CTRL_CHECK_VERSION = 49,
40 STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50,
41 INVOKEDYNAMIC_MAJOR_VERSION = 51,
42 NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52
43 };
44 typedef enum { ThrowException, NoException } Mode;
45
46 /**
47 * Verify the bytecodes for a class. If 'throw_exception' is true
48 * then the appropriate VerifyError or ClassFormatError will be thrown.
49 * Otherwise, no exception is thrown and the return indicates the
50 * error.
51 */
52 static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
289 u2 bci, bool this_uninit, StackMapFrame* current_frame,
290 StackMapTable* stackmap_table, TRAPS);
291
292 void verify_ldc(
293 int opcode, u2 index, StackMapFrame *current_frame,
294 constantPoolHandle cp, u2 bci, TRAPS);
295
296 void verify_switch(
297 RawBytecodeStream* bcs, u4 code_length, char* code_data,
298 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
299
300 void verify_field_instructions(
301 RawBytecodeStream* bcs, StackMapFrame* current_frame,
302 constantPoolHandle cp, TRAPS);
303
304 void verify_invoke_init(
305 RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
306 StackMapFrame* current_frame, u4 code_length, bool* this_uninit,
307 constantPoolHandle cp, TRAPS);
308
309 void verify_invoke_instructions(
310 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
311 bool* this_uninit, VerificationType return_type,
312 constantPoolHandle cp, TRAPS);
313
314 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
315 void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp,
316 StackMapFrame* current_frame, TRAPS);
317 void verify_return_value(
318 VerificationType return_type, VerificationType type, u2 offset,
319 StackMapFrame* current_frame, TRAPS);
320
321 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
322 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
323 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
324 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
325 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
326 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
327 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
328 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
|
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_CLASSFILE_VERIFIER_HPP
26 #define SHARE_VM_CLASSFILE_VERIFIER_HPP
27
28 #include "classfile/verificationType.hpp"
29 #include "memory/gcLocker.hpp"
30 #include "oops/klass.hpp"
31 #include "oops/method.hpp"
32 #include "runtime/handles.hpp"
33 #include "utilities/growableArray.hpp"
34 #include "utilities/exceptions.hpp"
35
36 // The verifier class
37 class Verifier : AllStatic {
38 public:
39 enum {
40 STRICTER_ACCESS_CTRL_CHECK_VERSION = 49,
41 STACKMAP_ATTRIBUTE_MAJOR_VERSION = 50,
42 INVOKEDYNAMIC_MAJOR_VERSION = 51,
43 NO_RELAX_ACCESS_CTRL_CHECK_VERSION = 52
44 };
45 typedef enum { ThrowException, NoException } Mode;
46
47 /**
48 * Verify the bytecodes for a class. If 'throw_exception' is true
49 * then the appropriate VerifyError or ClassFormatError will be thrown.
50 * Otherwise, no exception is thrown and the return indicates the
51 * error.
52 */
53 static bool verify(instanceKlassHandle klass, Mode mode, bool should_verify_class, TRAPS);
290 u2 bci, bool this_uninit, StackMapFrame* current_frame,
291 StackMapTable* stackmap_table, TRAPS);
292
293 void verify_ldc(
294 int opcode, u2 index, StackMapFrame *current_frame,
295 constantPoolHandle cp, u2 bci, TRAPS);
296
297 void verify_switch(
298 RawBytecodeStream* bcs, u4 code_length, char* code_data,
299 StackMapFrame* current_frame, StackMapTable* stackmap_table, TRAPS);
300
301 void verify_field_instructions(
302 RawBytecodeStream* bcs, StackMapFrame* current_frame,
303 constantPoolHandle cp, TRAPS);
304
305 void verify_invoke_init(
306 RawBytecodeStream* bcs, u2 ref_index, VerificationType ref_class_type,
307 StackMapFrame* current_frame, u4 code_length, bool* this_uninit,
308 constantPoolHandle cp, TRAPS);
309
310 // Used by ends_in_athrow() to save bytecode intervals.
311 void push_bci_offsets(GrowableArray<u4> *bci_stack_ptr,
312 u4 start_offset, u4 end_offset) {
313 bci_stack_ptr->push(start_offset);
314 bci_stack_ptr->push(end_offset);
315 }
316
317 // Used by ends_in_athrow() to retrieve start of saved bytecode interval.
318 u4 pop_bci_start_offset(GrowableArray<u4> *bci_stack_ptr) {
319 assert(!bci_stack_ptr->is_empty(), "Stack should not be empty");
320 assert(bci_stack_ptr->length() % 2 == 1,
321 "Stack should have odd number of entries");
322 return bci_stack_ptr->pop();
323 }
324
325 // Used by ends_in_athrow() to retrieve end of saved bytecode interval.
326 u4 pop_bci_end_offset(GrowableArray<u4> *bci_stack_ptr) {
327 assert(!bci_stack_ptr->is_empty(), "Stack should not be empty");
328 assert(bci_stack_ptr->length() % 2 == 0,
329 "Stack should have even number of entries");
330 return bci_stack_ptr->pop();
331 }
332
333 // Used by ends_in_athrow() to push all handlers that contain bci onto the
334 // handler_stack, if the handler is not already on the stack.
335 void push_handlers(GrowableArray<u4>* handler_stack, u4 bci);
336
337 // Returns true if all paths thru the specified bytecode stream end in athrow.
338 bool ends_in_athrow(u4 start_bc_offset, u4 end_bc_offset);
339
340 void verify_invoke_instructions(
341 RawBytecodeStream* bcs, u4 code_length, StackMapFrame* current_frame,
342 bool* this_uninit, VerificationType return_type,
343 constantPoolHandle cp, TRAPS);
344
345 VerificationType get_newarray_type(u2 index, u2 bci, TRAPS);
346 void verify_anewarray(u2 bci, u2 index, constantPoolHandle cp,
347 StackMapFrame* current_frame, TRAPS);
348 void verify_return_value(
349 VerificationType return_type, VerificationType type, u2 offset,
350 StackMapFrame* current_frame, TRAPS);
351
352 void verify_iload (u2 index, StackMapFrame* current_frame, TRAPS);
353 void verify_lload (u2 index, StackMapFrame* current_frame, TRAPS);
354 void verify_fload (u2 index, StackMapFrame* current_frame, TRAPS);
355 void verify_dload (u2 index, StackMapFrame* current_frame, TRAPS);
356 void verify_aload (u2 index, StackMapFrame* current_frame, TRAPS);
357 void verify_istore(u2 index, StackMapFrame* current_frame, TRAPS);
358 void verify_lstore(u2 index, StackMapFrame* current_frame, TRAPS);
359 void verify_fstore(u2 index, StackMapFrame* current_frame, TRAPS);
|