Skip to content

Commit 33e2a51

Browse files
committedNov 22, 2021
8265795: vmTestbase/nsk/jvmti/AttachOnDemand/attach022/TestDescription.java fails when running with JEP 416
Reviewed-by: sspitsyn, dholmes
1 parent 22f12ac commit 33e2a51

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed
 

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

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "oops/objArrayOop.inline.hpp"
4242
#include "oops/oop.inline.hpp"
4343
#include "oops/typeArrayOop.inline.hpp"
44+
#include "prims/jvmtiExport.hpp"
4445
#include "prims/unsafe.hpp"
4546
#include "runtime/globals.hpp"
4647
#include "runtime/handles.inline.hpp"
@@ -329,6 +330,7 @@ UNSAFE_LEAF(void, Unsafe_FullFence(JNIEnv *env, jobject unsafe)) {
329330
////// Allocation requests
330331

331332
UNSAFE_ENTRY(jobject, Unsafe_AllocateInstance(JNIEnv *env, jobject unsafe, jclass cls)) {
333+
JvmtiVMObjectAllocEventCollector oam;
332334
instanceOop i = InstanceKlass::allocate_instance(JNIHandles::resolve_non_null(cls), CHECK_NULL);
333335
return JNIHandles::make_local(THREAD, i);
334336
} UNSAFE_END

‎test/hotspot/jtreg/ProblemList.txt

-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
#
3939
#############################################################################
4040

41-
vmTestbase/nsk/jvmti/AttachOnDemand/attach002a/TestDescription.java 8265795 generic-all
42-
vmTestbase/nsk/jvmti/AttachOnDemand/attach022/TestDescription.java 8265795 generic-all
4341
vmTestbase/nsk/jdi/ObjectReference/referringObjects/referringObjects002/referringObjects002.java 8265796 generic-all
4442

4543
#############################################################################
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
/**
25+
* @test
26+
* @summary Verifies that a VMObjectAlloc event is generated for object created using MethodHandle
27+
* @requires vm.jvmti
28+
* @run main/othervm/native -agentlib:VMObjectAlloc VMObjectAllocTest
29+
*/
30+
31+
import java.lang.invoke.MethodHandle;
32+
import java.lang.invoke.MethodHandles;
33+
import java.lang.invoke.MethodType;
34+
35+
public class VMObjectAllocTest {
36+
37+
private static native int getNumberOfAllocation();
38+
39+
public VMObjectAllocTest(String str) {
40+
}
41+
42+
public static void main(String[] args) throws Throwable {
43+
44+
MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
45+
MethodType mt = MethodType.methodType(void.class, String.class);
46+
MethodHandle mh = publicLookup.findConstructor(VMObjectAllocTest.class, mt);
47+
mh.invoke("str");
48+
49+
if (getNumberOfAllocation() != 1) {
50+
throw new Exception("Number of allocation != 1");
51+
}
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
#include <string.h>
25+
#include "jvmti.h"
26+
27+
extern "C" {
28+
29+
static int number_of_allocation = 0;
30+
31+
extern JNIEXPORT void JNICALL
32+
VMObjectAlloc(jvmtiEnv *jvmti,
33+
JNIEnv* jni,
34+
jthread thread,
35+
jobject object,
36+
jclass cls,
37+
jlong size) {
38+
char *signature = NULL;
39+
jvmtiError err = jvmti->GetClassSignature(cls, &signature, NULL);
40+
if (err != JVMTI_ERROR_NONE) {
41+
jni->FatalError("Failed during the GetClassSignature call");
42+
}
43+
44+
printf("VMObjectAlloc called for %s\n", signature);
45+
46+
if (!strcmp(signature, "LVMObjectAllocTest;")) {
47+
number_of_allocation++;
48+
}
49+
}
50+
51+
52+
JNIEXPORT jint JNICALL
53+
Java_VMObjectAllocTest_getNumberOfAllocation(JNIEnv *env, jclass cls) {
54+
return number_of_allocation;
55+
}
56+
57+
extern JNIEXPORT jint JNICALL
58+
Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
59+
jvmtiEnv *jvmti;
60+
jvmtiEventCallbacks callbacks;
61+
jvmtiError err;
62+
jvmtiCapabilities caps;
63+
64+
if (jvm->GetEnv((void **) &jvmti, JVMTI_VERSION) != JNI_OK) {
65+
return JNI_ERR;
66+
}
67+
68+
memset(&callbacks, 0, sizeof(callbacks));
69+
callbacks.VMObjectAlloc = &VMObjectAlloc;
70+
memset(&caps, 0, sizeof(caps));
71+
caps.can_generate_vm_object_alloc_events = 1;
72+
73+
err = jvmti->AddCapabilities( &caps);
74+
if (err != JVMTI_ERROR_NONE) {
75+
return JNI_ERR;
76+
}
77+
78+
err = jvmti->SetEventCallbacks(&callbacks, sizeof(jvmtiEventCallbacks));
79+
if (err != JVMTI_ERROR_NONE) {
80+
return JNI_ERR;
81+
}
82+
83+
err = jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_VM_OBJECT_ALLOC , NULL);
84+
if (err != JVMTI_ERROR_NONE) {
85+
return JNI_ERR;
86+
}
87+
88+
return JNI_OK;
89+
}
90+
91+
} //extern "C"

0 commit comments

Comments
 (0)
Please sign in to comment.