File: VerifyTest1.j

package info (click to toggle)
jasmin-sable 1.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 1,464 kB
  • ctags: 1,903
  • sloc: java: 12,496; makefile: 126; csh: 93; sh: 93
file content (62 lines) | stat: -rw-r--r-- 1,942 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
; --- Copyright Jonathan Meyer 1996. All rights reserved. -----------------
; File:      jasmin/examples/VerifyTest1.j
; Author:    Jonathan Meyer, 10 July 1996
; Purpose:   Trys to pull one on the verifier
; -------------------------------------------------------------------------

; This file illustrates the bytecode verifier at work - the
; code in the example() method below seems reasonable, but
; Java's bytecode verifier will fail the code because the two points leading
; to the Loop label (from the top of the method and from the ifne
; statement) have different stack states.  Instead, a different approach
; must be adopted  - e.g. by allocating an array, or simply writing:
;
;    aconst_null
;    aconst_null
;    aconst_null
;    aconst_null

; Note that many interpreters will run this code OK if you don't use
; a verifier. The code itself is well behaved (it doesn't trash the
; interpreter), but the approach it uses is disallowed by the verifier.
;

; Compile the example, then run it using:
;
;     % java -verify VerifyTest1
;     VERIFIER ERROR VerifyTest1.example()V:
;     Inconsistent stack height 1 != 0
;

.class public examples/VerifyTest1
.super java/lang/Object

.method public <init>()V
   aload_0
   invokenonvirtual java/lang/Object/<init>()V
   return
.end method

.method public example()V
    .limit locals 2
    .limit stack  10

    ; this tries to push four nulls onto the stack
    ; using a loop - Java's verifier will fail this program

    iconst_4     ; store 4 in local variable 1 (used as a counter)
    istore_1

  Loop:
    aconst_null  ; push null onto the stack
    iinc 1 -1    ; decrement local variable 4 (the counter variable)
    iload_1
    ifne Loop    ; jump back to Loop unless the variable has reached 0

    return
.end method

.method public static main([Ljava/lang/String;)V
    ; - do nothing : this is only to illustrate the bytecode verifier at work.
    return
.end method