Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/lang/constant/DynamicCallSiteDescTest.java
66644 views
1
/*
2
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
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
import java.lang.invoke.MethodType;
25
import java.lang.constant.*;
26
import java.util.Arrays;
27
import java.util.List;
28
import java.util.stream.IntStream;
29
import java.util.stream.Stream;
30
31
import org.testng.annotations.Test;
32
33
import static java.lang.constant.ConstantDescs.CD_int;
34
import static java.lang.constant.ConstantDescs.CD_void;
35
import static java.util.stream.Collectors.joining;
36
import static java.util.stream.Collectors.toList;
37
import static org.testng.Assert.assertEquals;
38
import static org.testng.Assert.fail;
39
40
/**
41
* @test
42
* @compile DynamicCallSiteDescTest.java
43
* @run testng DynamicCallSiteDescTest
44
* @summary unit tests for java.lang.constant.DynamicCallSiteDesc
45
*/
46
47
@Test
48
public class DynamicCallSiteDescTest extends SymbolicDescTest {
49
/* note there is no unit test for method resolveCallSiteDesc as it is being tested in another test in this
50
* suite, IndyDescTest
51
*/
52
53
public void testOf() throws ReflectiveOperationException {
54
DirectMethodHandleDesc dmh = ConstantDescs.ofCallsiteBootstrap(
55
ClassDesc.of("BootstrapAndTarget"),
56
"bootstrap",
57
ClassDesc.of("java.lang.invoke.CallSite")
58
);
59
try {
60
DynamicCallSiteDesc.of(
61
dmh,
62
"",
63
MethodTypeDesc.ofDescriptor("()I")
64
);
65
fail("IllegalArgumentException expected");
66
} catch (IllegalArgumentException iae) {
67
// good
68
}
69
70
try {
71
DynamicCallSiteDesc.of(
72
null,
73
"getTarget",
74
MethodTypeDesc.ofDescriptor("()I")
75
);
76
fail("NullPointerException expected");
77
} catch (NullPointerException npe) {
78
// good
79
}
80
81
try {
82
DynamicCallSiteDesc.of(
83
dmh,
84
null,
85
MethodTypeDesc.ofDescriptor("()I")
86
);
87
fail("NullPointerException expected");
88
} catch (NullPointerException npe) {
89
// good
90
}
91
92
try {
93
DynamicCallSiteDesc.of(
94
dmh,
95
"getTarget",
96
null
97
);
98
fail("NullPointerException expected");
99
} catch (NullPointerException npe) {
100
// good
101
}
102
103
try {
104
DynamicCallSiteDesc.of(
105
dmh,
106
"getTarget",
107
MethodTypeDesc.ofDescriptor("()I"),
108
null
109
);
110
fail("NullPointerException expected");
111
} catch (NullPointerException npe) {
112
// good
113
}
114
try {
115
DynamicCallSiteDesc.of(
116
dmh,
117
"getTarget",
118
MethodTypeDesc.ofDescriptor("()I"),
119
new ConstantDesc[]{ null }
120
);
121
fail("NullPointerException expected");
122
} catch (NullPointerException npe) {
123
// good
124
}
125
}
126
127
public void testWithArgs() throws ReflectiveOperationException {
128
DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(
129
ClassDesc.of("BootstrapAndTarget"),
130
"bootstrap",
131
ClassDesc.of("java.lang.invoke.CallSite")
132
),
133
"getTarget",
134
MethodTypeDesc.ofDescriptor("()I")
135
);
136
137
try {
138
desc.withArgs(null);
139
fail("NullPointerException expected");
140
} catch (NullPointerException npe) {
141
// good
142
}
143
144
try {
145
desc.withArgs(new ConstantDesc[]{ null });
146
fail("NullPointerException expected");
147
} catch (NullPointerException npe) {
148
// good
149
}
150
}
151
152
public void testWithNameAndType() throws ReflectiveOperationException {
153
DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(
154
ClassDesc.of("BootstrapAndTarget"),
155
"bootstrap",
156
ClassDesc.of("java.lang.invoke.CallSite")
157
),
158
"getTarget",
159
MethodTypeDesc.ofDescriptor("()I")
160
);
161
162
try {
163
desc.withNameAndType(null, MethodTypeDesc.ofDescriptor("()I"));
164
fail("NullPointerException expected");
165
} catch (NullPointerException npe) {
166
// good
167
}
168
169
try {
170
desc.withNameAndType("bootstrap", null);
171
fail("NullPointerException expected");
172
} catch (NullPointerException npe) {
173
// good
174
}
175
}
176
177
public void testAccessorsAndFactories() throws ReflectiveOperationException {
178
DynamicCallSiteDesc desc = DynamicCallSiteDesc.of(ConstantDescs.ofCallsiteBootstrap(
179
ClassDesc.of("BootstrapAndTarget"),
180
"bootstrap",
181
ClassDesc.of("java.lang.invoke.CallSite")
182
),
183
"_",
184
MethodTypeDesc.ofDescriptor("()I")
185
);
186
assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(), desc.invocationType()));
187
assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(),
188
desc.invocationName(), desc.invocationType()));
189
assertEquals(desc, DynamicCallSiteDesc.of((DirectMethodHandleDesc)desc.bootstrapMethod(),
190
desc.invocationName(), desc.invocationType(), desc.bootstrapArgs()));
191
}
192
}
193
194