Skip to content

Commit 18d1272

Browse files
fparaindfuch
andcommittedSep 29, 2020
8253744: [lworld] [lw3] Injected IdentityObject interface should not be hidden by the JVM
Co-authored-by: Daniel Fuchs <dfuchs@openjdk.org> Reviewed-by: rriggs
1 parent e605c42 commit 18d1272

File tree

8 files changed

+190
-177
lines changed

8 files changed

+190
-177
lines changed
 

‎src/hotspot/share/prims/jvm.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -1288,9 +1288,6 @@ JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
12881288
if (klass->is_instance_klass()) {
12891289
InstanceKlass* ik = InstanceKlass::cast(klass);
12901290
size = ik->local_interfaces()->length();
1291-
if (ik->has_injected_identityObject()) {
1292-
size--;
1293-
}
12941291
} else {
12951292
assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
12961293
size = 3;
@@ -1302,13 +1299,10 @@ JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
13021299
// Fill in result
13031300
if (klass->is_instance_klass()) {
13041301
// Regular instance klass, fill in all local interfaces
1305-
int cursor = 0;
13061302
for (int index = 0; index < size; index++) {
13071303
InstanceKlass* ik = InstanceKlass::cast(klass);
13081304
Klass* k = ik->local_interfaces()->at(index);
1309-
if (!ik->has_injected_identityObject() || k != SystemDictionary::IdentityObject_klass()) {
1310-
result->obj_at_put(cursor++, k->java_mirror());
1311-
}
1305+
result->obj_at_put(index, k->java_mirror());
13121306
}
13131307
} else {
13141308
// All arrays implement java.lang.Cloneable, java.io.Serializable and java.lang.IdentityObject

‎src/hotspot/share/prims/jvmtiEnv.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -2656,18 +2656,14 @@ JvmtiEnv::GetImplementedInterfaces(oop k_mirror, jint* interface_count_ptr, jcla
26562656
InstanceKlass* ik = InstanceKlass::cast(k);
26572657
Array<InstanceKlass*>* interface_list = ik->local_interfaces();
26582658
int result_length = (interface_list == NULL ? 0 : interface_list->length());
2659-
if (ik->has_injected_identityObject()) result_length--;
26602659
jclass* result_list = (jclass*) jvmtiMalloc(result_length * sizeof(jclass));
2661-
int cursor = 0;
26622660
for (int i_index = 0; i_index < result_length; i_index += 1) {
26632661
InstanceKlass* klass_at = interface_list->at(i_index);
26642662
assert(klass_at->is_klass(), "interfaces must be Klass*s");
26652663
assert(klass_at->is_interface(), "interfaces must be interfaces");
2666-
if (klass_at != SystemDictionary::IdentityObject_klass() || !ik->has_injected_identityObject()) {
2667-
oop mirror_at = klass_at->java_mirror();
2668-
Handle handle_at = Handle(current_thread, mirror_at);
2669-
result_list[cursor++] = (jclass) jni_reference(handle_at);
2670-
}
2664+
oop mirror_at = klass_at->java_mirror();
2665+
Handle handle_at = Handle(current_thread, mirror_at);
2666+
result_list[i_index] = (jclass) jni_reference(handle_at);
26712667
}
26722668
*interface_count_ptr = result_length;
26732669
*interfaces_ptr = result_list;

‎test/hotspot/jtreg/runtime/valhalla/inlinetypes/identityObject/TestIdentityObject.java

+11-23
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636

3737
public class TestIdentityObject {
38-
static void checkIdentityObject(Class c, boolean subtype, boolean visible) {
38+
static void checkIdentityObject(Class c, boolean subtype) {
3939
boolean s;
4040
try {
4141
c.asSubclass(IdentityObject.class);
@@ -50,30 +50,18 @@ static void checkIdentityObject(Class c, boolean subtype, boolean visible) {
5050
throw new RuntimeException("Type " + c.getName() + " should not implements IdentityObject");
5151
}
5252
}
53-
boolean found = false;
54-
Class[] interfaces = c.getInterfaces();
55-
for(Class i : interfaces) {
56-
if (i == IdentityObject.class) found = true;
57-
}
58-
if (found != visible) {
59-
if (visible) {
60-
throw new RuntimeException("Type " + c.getName() + " should have IdentityObject visible, but it hasn't");
61-
} else {
62-
throw new RuntimeException("Type " + c.getName() + " should not have IdentityObject visible, but it has");
63-
}
64-
}
6553
}
6654

6755
public static void main(String[] args) {
68-
checkIdentityObject(InlineType.class, false, false);
69-
checkIdentityObject(IdentityType.class, true, false);
70-
checkIdentityObject(IdentityTypeImplementingIdentityObject.class, true, true);
71-
checkIdentityObject(Interface.class, false, false);
72-
checkIdentityObject(InterfaceExtendingIdentityObject.class, true, true);
73-
checkIdentityObject(AbstractTypeImplementingIdentityObject.class, true, true);
74-
checkIdentityObject(AbstractTypeWithNonstaticFields.class, true, false);
75-
checkIdentityObject(AbstractTypeWithStaticFields.class, false, false);
76-
checkIdentityObject(AbstractTypeWithSynchronizedNonstaticMethod.class, true, false);
77-
checkIdentityObject(AbstractTypeWithSynchronizedStaticMethod.class, false, false);
56+
checkIdentityObject(InlineType.class, false);
57+
checkIdentityObject(IdentityType.class, true);
58+
checkIdentityObject(IdentityTypeImplementingIdentityObject.class, true);
59+
checkIdentityObject(Interface.class, false);
60+
checkIdentityObject(InterfaceExtendingIdentityObject.class, true);
61+
checkIdentityObject(AbstractTypeImplementingIdentityObject.class, true);
62+
checkIdentityObject(AbstractTypeWithNonstaticFields.class, true);
63+
checkIdentityObject(AbstractTypeWithStaticFields.class, false);
64+
checkIdentityObject(AbstractTypeWithSynchronizedNonstaticMethod.class, true);
65+
checkIdentityObject(AbstractTypeWithSynchronizedStaticMethod.class, false);
7866
}
7967
}

‎test/hotspot/jtreg/serviceability/jvmti/HiddenClass/libHiddenClassSigTest.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern "C" {
2828

2929
static const char* EXP_INTERF_SIG = "LP/Q/HCInterf;";
3030
static const char* SIG_START = "LP/Q/HiddenClassSig";
31+
static const char* IDENTITYOBJECT_IF = "Ljava/lang/IdentityObject;";
3132
static const size_t SIG_START_LEN = strlen(SIG_START);
3233
static const int ACC_INTERFACE = 0x0200; // Interface class modifiers bit
3334

@@ -192,20 +193,26 @@ check_hidden_class_impl_interf(jvmtiEnv* jvmti, JNIEnv* jni, jclass klass) {
192193
jclass* interfaces = NULL;
193194
jvmtiError err;
194195

195-
// check that hidden class implements just one interface
196+
// check that hidden class implements just one interface (or two if IdentityObject has been injected)
196197
err = jvmti->GetImplementedInterfaces(klass, &count, &interfaces);
197198
CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetImplementedInterfaces");
198-
if (count != 1) {
199-
LOG1("check_hidden_class_impl_interf: FAIL: implemented interfaces count: %d, expected to be 1\n", count);
199+
if (count != 1 && count != 2) {
200+
LOG1("check_hidden_class_impl_interf: FAIL: implemented interfaces count: %d, expected to be in [1-2] range\n", count);
200201
failed = true;
201202
return;
202203
}
203-
// get interface signature
204-
err = jvmti->GetClassSignature(interfaces[0], &sig, NULL);
205-
CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetClassSignature for implemented interface");
204+
bool found = false;
205+
for (int i = 0; i < count; i++) {
206+
// get interface signature
207+
err = jvmti->GetClassSignature(interfaces[i], &sig, NULL);
208+
CHECK_JVMTI_ERROR(jni, err, "check_hidden_class_impl_interf: Error in JVMTI GetClassSignature for implemented interface");
209+
// check the interface signature is matching the expected
210+
if (strcmp(sig, EXP_INTERF_SIG) == 0) {
211+
found = true;
212+
}
213+
}
206214

207-
// check the interface signature is matching the expected
208-
if (strcmp(sig, EXP_INTERF_SIG) != 0) {
215+
if (!found) {
209216
LOG2("check_hidden_class_impl_interf: FAIL: implemented interface signature: %s, expected to be: %s\n",
210217
sig, EXP_INTERF_SIG);
211218
failed = true;

‎test/jdk/java/lang/invoke/defineHiddenClass/BasicTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public void hiddenClass() throws Throwable {
115115
Class<?>[] intfs = c.getInterfaces();
116116
assertTrue(c.isHidden());
117117
assertFalse(c.isPrimitive());
118-
assertTrue(intfs.length == 1);
119-
assertTrue(intfs[0] == HiddenTest.class);
118+
assertTrue(intfs.length == 1 || intfs.length == 2);
119+
assertTrue(intfs[0] == HiddenTest.class || (intfs.length == 2 && intfs[1] == HiddenTest.class));
120120
assertTrue(c.getCanonicalName() == null);
121121

122122
String hcName = "HiddenClass";
@@ -348,8 +348,8 @@ public void hiddenCantReflect() throws Throwable {
348348

349349
Class<?> c = t.getClass();
350350
Class<?>[] intfs = c.getInterfaces();
351-
assertTrue(intfs.length == 1);
352-
assertTrue(intfs[0] == HiddenTest.class);
351+
assertTrue(intfs.length == 1 || intfs.length == 2);
352+
assertTrue(intfs[0] == HiddenTest.class || (intfs.length == 2 && intfs[1] == HiddenTest.class));
353353

354354
try {
355355
// this would cause loading of class HiddenCantReflect and NCDFE due

‎test/jdk/javax/naming/module/RunBasic.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -67,7 +67,17 @@ public class RunBasic {
6767

6868
private static final List<String> JAVA_CMDS;
6969

70+
// To update .ldap files under src/test/test, LDAP request and response
71+
// bytes can be logged while interacting with a real LDAP server
72+
// (e.g.: HOST_NAME = "localhost:8389").
73+
// For that point HOST_NAME to a real server in which the ROOT_DOMAIN
74+
// below is configured to allow modifications by anonymous users, and
75+
// pass an additional "-trace" argument to the created subprocesses.
76+
// The LDAP requests and response bytes will appear in the log, and you
77+
// can then update the corresponding .ldap files.
7078
static final String HOST_NAME = InetAddress.getLoopbackAddress().getHostName();
79+
static final String ROOT_DOMAIN = "dc=ie,dc=oracle,dc=com";
80+
static final String PATH = "/" + ROOT_DOMAIN;
7181

7282
static {
7383
String javaPath = JDKToolFinder.getJDKTool("java");
@@ -119,8 +129,14 @@ private static void makeDir(String first, String... more)
119129

120130
private static void runTest(String desc, String clsName) throws Throwable {
121131
System.out.println("Running with the '" + desc + "' module...");
132+
// To record LDAP requests and responses in order to update the
133+
// .ldap files under src/test/test, make sure that HOST_NAME
134+
// points to an LDAP server accepting anonymous modifications without
135+
// credentials, and that has "dc=ie,dc=oracle,dc=com" configured
136+
// as root domain. Also add "-trace" as last argument to the runJava
137+
// command below.
122138
runJava("-Dtest.src=" + TEST_SRC, "-p", "mods", "-m", "test/" + clsName,
123-
"ldap://" + HOST_NAME + "/dc=ie,dc=oracle,dc=com");
139+
"ldap://" + HOST_NAME + PATH);
124140
}
125141

126142
private static void runJava(String... opts) throws Throwable {

‎test/jdk/javax/naming/module/src/test/test/StoreObject.ldap

+111-103
Large diffs are not rendered by default.

‎test/jdk/javax/naming/module/src/test/test/StoreRemote.ldap

+27-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
# Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
33
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
#
55
# This code is free software; you can redistribute it and/or modify it
@@ -136,10 +136,10 @@
136136
# : }
137137
# : }
138138
#
139-
0000: 30 82 03 17 02 01 02 68 82 02 F3 04 22 63 6E 3D 0......h...."cn=
139+
0000: 30 82 03 31 02 01 02 68 82 03 0D 04 22 63 6E 3D 0..1...h...."cn=
140140
0010: 6D 79 72 65 6D 6F 74 65 2C 64 63 3D 69 65 2C 64 myremote,dc=ie,d
141141
0020: 63 3D 6F 72 61 63 6C 65 2C 64 63 3D 63 6F 6D 30 c=oracle,dc=com0
142-
0030: 82 02 CB 30 82 01 58 04 12 6A 61 76 61 53 65 72 ...0..X..javaSer
142+
0030: 82 02 E5 30 82 01 58 04 12 6A 61 76 61 53 65 72 ...0..X..javaSer
143143
0040: 69 61 6C 69 7A 65 64 44 61 74 61 31 82 01 40 04 ializedData1..@.
144144
0050: 82 01 3C AC ED 00 05 73 72 00 1B 6F 72 67 2E 65 ..<....sr..org.e
145145
0060: 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E 48 65 6C xample.hello.Hel
@@ -165,8 +165,8 @@
165165
01A0: 04 03 74 6F 70 04 0D 6A 61 76 61 43 6F 6E 74 61 ..top..javaConta
166166
01B0: 69 6E 65 72 04 0A 6A 61 76 61 4F 62 6A 65 63 74 iner..javaObject
167167
01C0: 04 14 6A 61 76 61 53 65 72 69 61 6C 69 7A 65 64 ..javaSerialized
168-
01D0: 4F 62 6A 65 63 74 30 81 E3 04 0E 6A 61 76 61 43 Object0....javaC
169-
01E0: 6C 61 73 73 4E 61 6D 65 73 31 81 D0 04 1B 6F 72 lassNames1....or
168+
01D0: 4F 62 6A 65 63 74 30 81 FD 04 0E 6A 61 76 61 43 Object0....javaC
169+
01E0: 6C 61 73 73 4E 61 6D 65 73 31 81 EA 04 1B 6F 72 lassNames1....or
170170
01F0: 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E g.example.hello.
171171
0200: 48 65 6C 6C 6F 49 6D 70 6C 04 23 6A 61 76 61 2E HelloImpl.#java.
172172
0210: 72 6D 69 2E 73 65 72 76 65 72 2E 55 6E 69 63 61 rmi.server.Unica
@@ -178,14 +178,16 @@
178178
0270: 2E 6C 61 6E 67 2E 4F 62 6A 65 63 74 04 0F 6A 61 .lang.Object..ja
179179
0280: 76 61 2E 72 6D 69 2E 52 65 6D 6F 74 65 04 14 6A va.rmi.Remote..j
180180
0290: 61 76 61 2E 69 6F 2E 53 65 72 69 61 6C 69 7A 61 ava.io.Serializa
181-
02A0: 62 6C 65 04 17 6F 72 67 2E 65 78 61 6D 70 6C 65 ble..org.example
182-
02B0: 2E 68 65 6C 6C 6F 2E 48 65 6C 6C 6F 30 2E 04 0D .hello.Hello0...
183-
02C0: 6A 61 76 61 43 6C 61 73 73 4E 61 6D 65 31 1D 04 javaClassName1..
184-
02D0: 1B 6F 72 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C .org.example.hel
185-
02E0: 6C 6F 2E 48 65 6C 6C 6F 49 6D 70 6C 30 10 04 02 lo.HelloImpl0...
186-
02F0: 63 6E 31 0A 04 08 6D 79 72 65 6D 6F 74 65 A0 1B cn1...myremote..
187-
0300: 30 19 04 17 32 2E 31 36 2E 38 34 30 2E 31 2E 31 0...2.16.840.1.1
188-
0310: 31 33 37 33 30 2E 33 2E 34 2E 32 13730.3.4.2
181+
02A0: 62 6C 65 04 18 6A 61 76 61 2E 6C 61 6E 67 2E 49 ble..java.lang.I
182+
02B0: 64 65 6E 74 69 74 79 4F 62 6A 65 63 74 04 17 6F dentityObject..o
183+
02C0: 72 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F rg.example.hello
184+
02D0: 2E 48 65 6C 6C 6F 30 2E 04 0D 6A 61 76 61 43 6C .Hello0...javaCl
185+
02E0: 61 73 73 4E 61 6D 65 31 1D 04 1B 6F 72 67 2E 65 assName1...org.e
186+
02F0: 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E 48 65 6C xample.hello.Hel
187+
0300: 6C 6F 49 6D 70 6C 30 10 04 02 63 6E 31 0A 04 08 loImpl0...cn1...
188+
0310: 6D 79 72 65 6D 6F 74 65 A0 1B 30 19 04 17 32 2E myremote..0...2.
189+
0320: 31 36 2E 38 34 30 2E 31 2E 31 31 33 37 33 30 2E 16.840.1.113730.
190+
0330: 33 2E 34 2E 32 3.4.2
189191

190192
# LDAP AddResponse:
191193
#
@@ -301,10 +303,10 @@
301303
# : }
302304
# : }
303305
#
304-
0000: 30 82 02 FA 02 01 03 64 82 02 F3 04 22 63 6E 3D 0......d...."cn=
306+
0000: 30 82 03 14 02 01 03 64 82 03 0D 04 22 63 6E 3D 0......d...."cn=
305307
0010: 6D 79 72 65 6D 6F 74 65 2C 64 63 3D 69 65 2C 64 myremote,dc=ie,d
306308
0020: 63 3D 6F 72 61 63 6C 65 2C 64 63 3D 63 6F 6D 30 c=oracle,dc=com0
307-
0030: 82 02 CB 30 82 01 58 04 12 6A 61 76 61 53 65 72 ...0..X..javaSer
309+
0030: 82 02 E5 30 82 01 58 04 12 6A 61 76 61 53 65 72 ...0..X..javaSer
308310
0040: 69 61 6C 69 7A 65 64 44 61 74 61 31 82 01 40 04 ializedData1..@.
309311
0050: 82 01 3C AC ED 00 05 73 72 00 1B 6F 72 67 2E 65 ..<....sr..org.e
310312
0060: 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E 48 65 6C xample.hello.Hel
@@ -330,8 +332,8 @@
330332
01A0: 04 03 74 6F 70 04 0D 6A 61 76 61 43 6F 6E 74 61 ..top..javaConta
331333
01B0: 69 6E 65 72 04 0A 6A 61 76 61 4F 62 6A 65 63 74 iner..javaObject
332334
01C0: 04 14 6A 61 76 61 53 65 72 69 61 6C 69 7A 65 64 ..javaSerialized
333-
01D0: 4F 62 6A 65 63 74 30 81 E3 04 0E 6A 61 76 61 43 Object0....javaC
334-
01E0: 6C 61 73 73 4E 61 6D 65 73 31 81 D0 04 1B 6F 72 lassNames1....or
335+
01D0: 4F 62 6A 65 63 74 30 81 FD 04 0E 6A 61 76 61 43 Object0....javaC
336+
01E0: 6C 61 73 73 4E 61 6D 65 73 31 81 EA 04 1B 6F 72 lassNames1....or
335337
01F0: 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E g.example.hello.
336338
0200: 48 65 6C 6C 6F 49 6D 70 6C 04 23 6A 61 76 61 2E HelloImpl.#java.
337339
0210: 72 6D 69 2E 73 65 72 76 65 72 2E 55 6E 69 63 61 rmi.server.Unica
@@ -343,12 +345,14 @@
343345
0270: 2E 6C 61 6E 67 2E 4F 62 6A 65 63 74 04 0F 6A 61 .lang.Object..ja
344346
0280: 76 61 2E 72 6D 69 2E 52 65 6D 6F 74 65 04 14 6A va.rmi.Remote..j
345347
0290: 61 76 61 2E 69 6F 2E 53 65 72 69 61 6C 69 7A 61 ava.io.Serializa
346-
02A0: 62 6C 65 04 17 6F 72 67 2E 65 78 61 6D 70 6C 65 ble..org.example
347-
02B0: 2E 68 65 6C 6C 6F 2E 48 65 6C 6C 6F 30 2E 04 0D .hello.Hello0...
348-
02C0: 6A 61 76 61 43 6C 61 73 73 4E 61 6D 65 31 1D 04 javaClassName1..
349-
02D0: 1B 6F 72 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C .org.example.hel
350-
02E0: 6C 6F 2E 48 65 6C 6C 6F 49 6D 70 6C 30 10 04 02 lo.HelloImpl0...
351-
02F0: 63 6E 31 0A 04 08 6D 79 72 65 6D 6F 74 65 cn1...myremote
348+
02A0: 62 6C 65 04 18 6A 61 76 61 2E 6C 61 6E 67 2E 49 ble..java.lang.I
349+
02B0: 64 65 6E 74 69 74 79 4F 62 6A 65 63 74 04 17 6F dentityObject..o
350+
02C0: 72 67 2E 65 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F rg.example.hello
351+
02D0: 2E 48 65 6C 6C 6F 30 2E 04 0D 6A 61 76 61 43 6C .Hello0...javaCl
352+
02E0: 61 73 73 4E 61 6D 65 31 1D 04 1B 6F 72 67 2E 65 assName1...org.e
353+
02F0: 78 61 6D 70 6C 65 2E 68 65 6C 6C 6F 2E 48 65 6C xample.hello.Hel
354+
0300: 6C 6F 49 6D 70 6C 30 10 04 02 63 6E 31 0A 04 08 loImpl0...cn1...
355+
0310: 6D 79 72 65 6D 6F 74 65 myremote
352356

353357
# LDAP SearchResultDone:
354358
#

0 commit comments

Comments
 (0)
Please sign in to comment.