summaryrefslogtreecommitdiff
path: root/dx/tests/087-ssa-local-vars/Blort.java
blob: 7ce8a91fc2bacd75ca09a51d609a0d388de45006 (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import java.io.IOException;
class Blort {
    private static void arrayCopyTest(int k) {
        // A local variable assigned from an argument
        int j = k;
        // These two locals are defined once and used multiple times
        String[] stringArray = new String[8];
        Object[] objectArray = new Object[8];
        // Should cause another move to be inserted
        Object anotherOne = objectArray;

        if (anotherOne != null) {
            System.out.println("foo");
        }

        // "i" is used in a loop
        for (int i = 0; i < stringArray.length; i++)
            stringArray[i] = new String(Integer.toString(i));

        System.out.println("string -> object");
        System.arraycopy(stringArray, 0, objectArray, 0, stringArray.length);
        System.out.println("object -> string");
        System.arraycopy(objectArray, 0, stringArray, 0, stringArray.length);
        System.out.println("object -> string (modified)");
        objectArray[4] = new Object();
        try {
            System.arraycopy(objectArray, 0, stringArray, 0,stringArray.length);
        } catch (ArrayStoreException ase) {
            // "ase" is an unused local which still must be preserved
            System.out.println("caught ArrayStoreException (expected)");
        }
    }

    private void testConstructor() {
        Blort foo = null;
        try {
            foo = new Blort();
        } catch (Exception ex) {
        }
        System.err.println(foo);
    }
    /**
     * Stolen from
     * java/android/org/apache/http/impl/io/AbstractMessageParser.java
     * Simplified.
     *
     * Checks to see that local variable assignment is preserved through
     * phi's. The key component here is the assignment of previous = current.
     */
    public static void parseHeaderGroup(
            final Object headGroup,
            final Object inbuffer,
            int maxHeaderCount,
            int maxLineLen)
        throws  IOException {

        StringBuilder current = null;
        StringBuilder previous = null;
        for (;;) {
            if (current == null) {
                current = new StringBuilder(64);
            } else {
                current.length();
            }
            int l = inbuffer.hashCode();
            if (l == -1 || current.length() < 1) {
                break;
            }

            if ((current.charAt(0) == ' ' || current.charAt(0) == '\t') && previous != null) {
                int i = 0;
                while (i < current.length()) {
                    char ch = current.charAt(i);
                    if (ch != ' ' && ch != '\t') {
                        break;
                    }
                    i++;
                }
                if (maxLineLen > 0
                        && previous.length() + 1 + current.length() - i > maxLineLen) {
                    throw new IOException("Maximum line length limit exceeded");
                }
                previous.append(' ');
                previous.append(current, i, current.length() - i);
            } else {
                previous = current;
                current = null;
            }
            if (maxHeaderCount > 0) {
                throw new IOException("Maximum header count exceeded");
            }
        }
    }
}