forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Alpha.java
101 lines (80 loc) · 2.31 KB
/
Alpha.java
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
95
96
97
98
99
100
101
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.redextest;
public class Alpha {
public Alpha(int v) {
x = v;
}
private static int x;
public class Beta {
public int doublex() {
return 2 * x;
}
}
}
/*
This example below is designed to make sure we do not remove synthetic
methods that refer to non-concrete fields. The invoke-static that
arises from the use of this.out creates a reference to a field that
is defined in a different compilation unit (java.io.FilterWriter):
0004fc: 5410 0200 |0000: iget-object v0, v1, Lcom/facebook/redextest/Gamma$Delta;.this$0:Lcom/facebook/redextest/Gamma; // field@0002
000500: 7110 0b00 0000 |0002: invoke-static {v0}, Lcom/facebook/redextest/Gamma;.access$000:(Lcom/facebook/redextest/Gamma;)Ljava/io/Writer; // method@000b
000506: 0c00 |0005: move-result-object v0
000508: 1100 |0006: return-object v0
We must not optimize this synthetic getter. If we do we get a bad access to
a protected field when getWriter is called:
invoke-virtual {v2}, Lcom/facebook/redextest/Gamma$Delta;.getWriter:()Ljava/io/Writer; // method@0008
*/
class Gamma extends java.io.FilterWriter {
public Gamma(java.io.Writer writer) {
super(writer);
}
class Delta {
public java.io.Writer getWriter() {
return out;
}
}
}
/*
The class SyntheticConstructor is added to test whether the const/4 insn
before calling a synthetic constructor can be removed by LocalDcePass
*/
class SyntheticConstructor {
public SyntheticConstructor(int i) {
x = i;
}
private static int x;
private SyntheticConstructor() {
x = 1;
}
public class InnerClass {
private SyntheticConstructor sc;
public InnerClass() {
sc = new SyntheticConstructor();
}
public int getValue() {
return sc.x;
}
}
}
class Delta {
public void foo() {
Epsilon.wrapper();
}
}
class Epsilon {
public static void wrapper() {
try {
target();
} catch (Throwable t) {
}
}
public static void target() {
// some code...
java.lang.Integer.parseInt("CrashMe");
}
}